jakaskerl
Sorry for reviving a solved thread, but I am running into an issue with RGB depth alignment that I think may be due to the way I am undistorting the color image.
I would like the pipeline to output RGB and disparity frames that are aligned. I am trying to do this within the StereoDepth node since the documentation states it has better performance than the ImageManip node. But when I try to use stereo.setDepthAlign() I get an error for incompatible function arguments. Is there a simple way to accomplish the RGB depth alignment within the StereoDepth node while still undistorting the RGB image?
I attached the pipeline I'm trying to use for this.
Apologies if this is something simple that I overlooked but I just can't seem to get it working.
import depthai as dai
import numpy as np
import cv2
from datetime import timedelta
def main():
# Create the pipeline
pipeline = dai.Pipeline()
# Create the nodes
monoLeft = pipeline.create(dai.node.MonoCamera)
monoRight = pipeline.create(dai.node.MonoCamera)
color = pipeline.create(dai.node.Camera)
stereo = pipeline.create(dai.node.StereoDepth)
sync = pipeline.create(dai.node.Sync)
xoutGrp = pipeline.create(dai.node.XLinkOut)
# Set the properties for the color camera
color.setBoardSocket(dai.CameraBoardSocket.CAM_A)
color.setSize((1280, 800))
color.setCalibrationAlpha(1.0) # Prevents the crop when resizing
color.setVideoSize((640, 400)) # Resize workaround due to bug
# Set the properties for the mono cameras
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoLeft.setCamera("left")
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoRight.setCamera("right")
# Set the properties for the stereo
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.DEFAULT)
stereo.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_3x3)
sub_pixel_active = True
stereo.initialConfig.setSubpixel(sub_pixel_active)
stereo.initialConfig.setSubpixelFractionalBits(3)
stereo.initialConfig.setLeftRightCheck(True)
stereo.initialConfig.setConfidenceThreshold(230)
stereo.initialConfig.setDepthAlign(dai.CameraBoardSocket.CAM_A)
# Set the properties for the sync
sync.setSyncThreshold(timedelta(milliseconds=30))
sync.setSyncAttempts(-1) # Default, ensures node only sends message if successfully synchronized
# Set the properties for the xlinkout
xoutGrp.setStreamName("xout")
# Link the nodes
monoLeft.out.link(stereo.left)
monoRight.out.link(stereo.right)
stereo.disparity.link(sync.inputs["disparity"])
color.video.link(sync.inputs["video"])
sync.out.link(xoutGrp.input)
disparityMultiplier = 255.0 / stereo.initialConfig.getMaxDisparity()
with dai.Device(pipeline) as device:
queue = device.getOutputQueue("xout", 1, False)
while True:
msgGrp = queue.get()
for name, msg in msgGrp:
frame = msg.getCvFrame()
if name == "disparity":
frame = (frame * disparityMultiplier).astype(np.uint8)
frame = cv2.applyColorMap(frame, cv2.COLORMAP_JET)
cv2.imshow(name, frame)
if cv2.waitKey(1) == ord("q"):
break
if __name__ == '__main__':
main()