演示

管道
源代码
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5import numpy as np
6
7device = dai.Device()
8calibration = device.getCalibration()
9pipeline = dai.Pipeline(device)
10monoLeft = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
11monoRight = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
12stereo = pipeline.create(dai.node.StereoDepth)
13
14# Linking
15monoLeftOut = monoLeft.requestFullResolutionOutput()
16monoRightOut = monoRight.requestFullResolutionOutput()
17monoLeftOut.link(stereo.left)
18monoRightOut.link(stereo.right)
19
20stereo.setRectification(True)
21stereo.setExtendedDisparity(True)
22stereo.setLeftRightCheck(True)
23
24rectifiedLeftQueue = stereo.rectifiedLeft.createOutputQueue()
25rectifiedRightQueue = stereo.rectifiedRight.createOutputQueue()
26depthQueue = stereo.depth.createOutputQueue()
27
28with pipeline:
29 pipeline.start()
30 while pipeline.isRunning():
31 leftRectified = rectifiedLeftQueue.get()
32 rightRectified = rectifiedRightQueue.get()
33 depth = depthQueue.get()
34 assert isinstance(leftRectified, dai.ImgFrame)
35 assert isinstance(rightRectified, dai.ImgFrame)
36 assert isinstance(depth, dai.ImgFrame)
37 cv2.imshow("left", leftRectified.getCvFrame())
38 cv2.imshow("right", rightRectified.getCvFrame())
39 colorizedDepth = dai.utility.colorizeDepthFrame(depth).getCvFrame()
40 cv2.imshow("depth", colorizedDepth)
41 key = cv2.waitKey(1)
42 if key == ord('q'):
43 pipeline.stop()
44 break
45 elif key == ord('u'):
46 randomDistortionCoeffs = np.random.rand(14)
47 calibration.setDistortionCoefficients(dai.CameraBoardSocket.CAM_B, randomDistortionCoeffs)
48 calibration.setDistortionCoefficients(dai.CameraBoardSocket.CAM_C, randomDistortionCoeffs)
49 try:
50 device.setCalibration(calibration)
51 except:
52 print("Failed to update calibration!")
53 try:
54 updatedCalib = device.getCalibration()
55 distortionCoeffs = updatedCalib.getDistortionCoefficients(dai.CameraBoardSocket.CAM_C)
56 print("Updated distortion coefficients: ", distortionCoeffs)
57 except:
58 pass需要帮助?
请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。