Currently I'm not able to try it on my machine, because it is deployed in customer location.
simplified pipeline looks like this:
pipeline = dai.Pipeline()
Define sources and outputs
camRgb = pipeline. Create(dai.node.ColorCamera)
manipSquare = pipeline. Create(dai.node.ImageManip)
spatialDetectionNetwork = pipeline.create(dai.node.YoloSpatialDetectionNetwork)
monoLeft = pipeline.create(dai.node.MonoCamera)
monoRight = pipeline. Create(dai.node.MonoCamera)
stereoDepth = pipeline. Create(dai.node.StereoDepth)
objectTracker = pipeline.create(dai.node.ObjectTracker)
manipOut = pipeline. Create(dai.node.ImageManip)
xoutPreview = pipeline. Create(dai.node.XLinkOut)
xoutTracklets = pipeline.create(dai.node.XLinkOut)
xoutPreview.setStreamName("preview")
xoutTracklets.setStreamName("tracklets")
Properties
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) # THE_1080_P / THE_4_K / THE_12_MP
camRgb.setIspScale(432, 1080) # 1920x1080 -> 576x324 or 432 or 540 or 648 or 756 or 864 or 972 or 1080
camRgb.setInterleaved(False)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR)
camRgb.setFps(20)
mono
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)
setting stereoDepth
stereoDepth.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
stereoDepth.setDepthAlign(dai.CameraBoardSocket.RGB)
stereoDepth.setOutputSize(monoLeft.getResolutionWidth(), monoLeft.getResolutionHeight())
spatialDetectionNetwork
Custom trained yolo tiny model (416x416) with one class
spatialDetectionNetwork.setBlobPath(config['blob_path'])
spatialDetectionNetwork.input.setBlocking(False)
spatialDetectionNetwork.setBoundingBoxScaleFactor(0.5)
spatialDetectionNetwork.setDepthLowerThreshold(500) # 50 cm
spatialDetectionNetwork.setDepthUpperThreshold(5000) # 5 m
Yolo specific parameters
metadata = config.get("NN_specific_metadata", {})
spatialDetectionNetwork.setNumClasses(1)
spatialDetectionNetwork.setCoordinateSize(metadata['coordinates'])
spatialDetectionNetwork.setAnchors(metadata['anchors'])
spatialDetectionNetwork.setAnchorMasks(metadata['anchor_masks'])
spatialDetectionNetwork.setIouThreshold(0.1)
spatialDetectionNetwork.setConfidenceThreshold(0.5)
objectTracker
objectTracker.setDetectionLabelsToTrack(config['track_labels'])
other tracking types did not help:
- ZERO_TERM_IMAGELESS
- SHORT_TERM_IMAGELESS
- SHORT_TERM_KCF
objectTracker.setTrackerType(dai.TrackerType.ZERO_TERM_COLOR_HISTOGRAM)
objectTracker.setTrackerIdAssignmentPolicy(dai.TrackerIdAssignmentPolicy.UNIQUE_ID)
objectTracker.inputTrackerFrame.setBlocking(False)
objectTracker.inputTrackerFrame.setQueueSize(4)
set input resize node
input_size = (416, 416)
manipSquare.initialConfig.setResize(int(input_size[0]), int(input_size[1]))
manipSquare.initialConfig.setFrameType(dai.ImgFrame.Type.BGR888p) # NV12,YUV420p,BGR888p
keep_aspect_ratio = False
manipSquare.initialConfig.setKeepAspectRatio(keep_aspect_ratio)
set output manip node
manipOut.initialConfig.setResize(int(int(input_size[0])*1920/1080), int(input_size[1]))
manipOut.initialConfig.setKeepAspectRatio(False)
linking
camRgb.isp.link(manipSquare.inputImage)
manipSquare.out.link(spatialDetectionNetwork.input)
spatialDetectionNetwork.passthrough.link(objectTracker.inputTrackerFrame)
spatialDetectionNetwork.passthrough.link(objectTracker.inputDetectionFrame)
spatialDetectionNetwork.out.link(objectTracker.inputDetections)
monoLeft.out.link(stereoDepth.left)
monoRight.out.link(stereoDepth.right)
stereoDepth.depth.link(spatialDetectionNetwork.inputDepth)
objectTracker.out.link(xoutTracklets.input)
objectTracker.passthroughTrackerFrame.link(manipOut.inputImage)
manipOut.out.link(xoutPreview.input)