Neural Depth Minimal
Supported on:RVC4
Pipeline
Source code
Python
C++
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5import numpy as np
6
7FPS = 10
8
9# Create pipeline
10with dai.Pipeline() as pipeline:
11 cameraLeft = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B, sensorFps=FPS)
12 cameraRight = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C, sensorFps=FPS)
13 leftOutput = cameraLeft.requestFullResolutionOutput()
14 rightOutput = cameraRight.requestFullResolutionOutput()
15
16 neuralDepth = pipeline.create(dai.node.NeuralDepth).build(leftOutput, rightOutput, dai.DeviceModelZoo.NEURAL_DEPTH_LARGE)
17
18 disparityQueue = neuralDepth.disparity.createOutputQueue()
19
20 # Connect to device and start pipeline
21 pipeline.start()
22 maxDisparity = 1
23 colorMap = cv2.applyColorMap(np.arange(256, dtype=np.uint8), cv2.COLORMAP_JET)
24 colorMap[0] = [0, 0, 0] # to make zero-disparity pixels black
25
26 while pipeline.isRunning():
27 disparityData = disparityQueue.get()
28 assert isinstance(disparityData, dai.ImgFrame)
29 npDisparity = disparityData.getFrame()
30 maxDisparity = max(maxDisparity, np.max(npDisparity))
31 colorizedDisparity = cv2.applyColorMap(((npDisparity / maxDisparity) * 255).astype(np.uint8), colorMap)
32 cv2.imshow("disparity", colorizedDisparity)
33
34 key = cv2.waitKey(1)
35 if key == ord('q'):
36 pipeline.stop()
37 break
38
39 if cv2.waitKey(1) == ord('q'):
40 breakNeed assistance?
Head over to Discussion Forum for technical support or any other questions you might have.