luxonis / depthai-python

DepthAI Python Library
MIT License
336 stars 185 forks source link

OAK-D LR not working when link left and right cameras #946

Closed arhitiron closed 5 months ago

arhitiron commented 5 months ago

I bought a camera oak-d lr, and tried the example from https://github.com/luxonis/depthai-python/blob/main/examples/StereoDepth/depth_preview_lr.py but for left and right cameras. Seems like it blocks and doesn't return queue names from queueNames = device.getQueueEvents(). In case I link left and center it works. Any ideas why that could happen? Or maybe some docs?

Additional info: MxId: 1844301091C547F500 USB speed: UsbSpeed.SUPER Connected cameras: [<CameraBoardSocket.RGB: 0>, <CameraBoardSocket.LEFT: 1>, <CameraBoardSocket.RIGHT: 2>]

import cv2
import depthai as dai
import numpy as np

# Closer-in minimum depth, disparity range is doubled (from 95 to 190):
extended_disparity = True
# Better accuracy for longer distance, fractional disparity 32-levels:
subpixel = True
# Better handling for occlusions:
lr_check = True

enableRectified = False

# Create pipeline
pipeline = dai.Pipeline()

# Define sources and outputs
left = pipeline.create(dai.node.ColorCamera)
right = pipeline.create(dai.node.ColorCamera)
LR_depth = pipeline.create(dai.node.StereoDepth)

xout_LR = pipeline.create(dai.node.XLinkOut)

xout_LR.setStreamName("disparity_LR")
if enableRectified:
    xoutl_LR = pipeline.create(dai.node.XLinkOut)
    xoutr_LR = pipeline.create(dai.node.XLinkOut)
    xoutl_LR.setStreamName("rectifiedLeft_LR")
    xoutr_LR.setStreamName("rectifiedRight_LR")

# Properties
left.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
left.setCamera("left")
left.setIspScale(2, 3)

right.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
right.setCamera("right")
right.setIspScale(2, 3)

LR_depth.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
LR_depth.initialConfig.setMedianFilter(dai.MedianFilter.MEDIAN_OFF)
LR_depth.setLeftRightCheck(lr_check)
LR_depth.setExtendedDisparity(extended_disparity)
LR_depth.setSubpixel(subpixel)

# Linking
# LR
left.isp.link(LR_depth.left)
right.isp.link(LR_depth.right)

LR_depth.disparity.link(xout_LR.input)
if enableRectified:
    LR_depth.rectifiedLeft.link(xoutl_LR.input)
    LR_depth.rectifiedRight.link(xoutr_LR.input)

maxDisp = LR_depth.initialConfig.getMaxDisparity()

# Connect to device and start pipeline
with dai.Device(pipeline) as device:
    while not device.isClosed():
        queueNames = device.getQueueEvents()
        print(f"queueNames: {queueNames}")
        for q in queueNames:
            message = device.getOutputQueue(q).get()
            # Display arrived frames
            if type(message) == dai.ImgFrame:
                frame = message.getCvFrame()
                if 'disparity' in q:
                    disp = (frame * (255.0 / maxDisp)).astype(np.uint8)
                    disp = cv2.applyColorMap(disp, cv2.COLORMAP_JET)
                    cv2.imshow(q, disp)
                else:
                    cv2.imshow(q, frame)
        if cv2.waitKey(1) == ord('q'):
            break
arhitiron commented 5 months ago

After update via pip install depthai --upgrade from 2.20.2.0 to 2.24.0.0 problem solved