DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Casting NN Blur
  • Demo
  • Setup
  • Source code

Casting NN Blur

This example demonstrates how to apply a blur effect using a neural network and the Cast node. The output of the cast node can be used in second stage neural networks or for further processing.

Demo

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python
C++
Python
GitHub
1import depthai as dai
2import cv2
3from pathlib import Path
4
5SHAPE = 300
6
7p = dai.Pipeline()
8
9camRgb = p.create(dai.node.ColorCamera)
10nn = p.create(dai.node.NeuralNetwork)
11rgbOut = p.create(dai.node.XLinkOut)
12cast = p.create(dai.node.Cast)
13castXout = p.create(dai.node.XLinkOut)
14
15camRgb.setPreviewSize(SHAPE, SHAPE)
16camRgb.setInterleaved(False)
17
18nnBlobPath = (Path(__file__).parent / Path('../models/blur_simplified_openvino_2021.4_6shave.blob')).resolve().absolute()
19
20nn.setBlobPath(nnBlobPath)
21
22rgbOut.setStreamName("rgb")
23
24castXout.setStreamName("cast")
25
26cast.setOutputFrameType(dai.RawImgFrame.Type.BGR888p)
27
28# Linking
29camRgb.preview.link(nn.input)
30camRgb.preview.link(rgbOut.input)
31nn.out.link(cast.input)
32cast.output.link(castXout.input)
33
34with dai.Device(p) as device:
35    qCam = device.getOutputQueue(name="rgb", maxSize=4, blocking=False)
36    qCast = device.getOutputQueue(name="cast", maxSize=4, blocking=False)
37
38
39    while True:
40        inCast = qCast.get()
41        assert isinstance(inCast, dai.ImgFrame)
42        inRgb = qCam.get()
43        assert isinstance(inRgb, dai.ImgFrame)
44        cv2.imshow("Blur", inCast.getCvFrame())
45        cv2.imshow("Original", inRgb.getCvFrame())
46
47
48        if cv2.waitKey(1) == ord('q'):
49            break

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.