# create depthai pipeline def createPipeline(): print('Creating Pipeline') # Start defining a pipeline pipeline = dai.Pipeline() # Define color camera camRgb = pipeline.createColorCamera() camRgb.setPreviewSize(640, 480) camRgb.setBoardSocket(dai.CameraBoardSocket.RGB) camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR) # Define a source - two mono (grayscale) cameras monoLeft = pipeline.createMonoCamera() monoRight = pipeline.createMonoCamera() stereo = pipeline.createStereoDepth() spatialLocationCalculator = pipeline.createSpatialLocationCalculator() # MonoCamera monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT) monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT) outputDepth = True outputRectified = False lrcheck = False subpixel = False # Create outputs xoutPreview = pipeline.createXLinkOut() xoutDepth = pipeline.createXLinkOut() xoutSpatialData = pipeline.createXLinkOut() xinSpatialCalcConfig = pipeline.createXLinkIn() xoutPreview.setStreamName("preview") xoutDepth.setStreamName("depth") xoutSpatialData.setStreamName("spatialData") xinSpatialCalcConfig.setStreamName("spatialCalcConfig") # StereoDepth stereo.setOutputDepth(outputDepth) stereo.setOutputRectified(outputRectified) stereo.setConfidenceThreshold(255) stereo.setLeftRightCheck(lrcheck) stereo.setSubpixel(subpixel) monoLeft.out.link(stereo.left) monoRight.out.link(stereo.right) spatialLocationCalculator.passthroughDepth.link(xoutDepth.input) stereo.depth.link(spatialLocationCalculator.inputDepth) topLeft = dai.Point2f(0.4, 0.4) bottomRight = dai.Point2f(0.8, 0.8) spatialLocationCalculator.setWaitForConfigInput(False) config = dai.SpatialLocationCalculatorConfigData() config.depthThresholds.lowerThreshold = 100 config.depthThresholds.upperThreshold = 10000 config.roi = dai.Rect(topLeft, bottomRight) spatialLocationCalculator.initialConfig.addROI(config) spatialLocationCalculator.out.link(xoutSpatialData.input) xinSpatialCalcConfig.out.link(spatialLocationCalculator.inputConfig) camRgb.preview.link(xoutPreview.input) return pipeline, topLeft, bottomRight, config