Hi!
I'm using the LR sensor and want to crop to get it down the needed width of 1280 for stereo-matching thus reducing fov instead of downscaling. Just wanted to make sure I'm doing it in the correct way since there are no examples. I mostly use c++ but I did this test in python.
#!/usr/bin/env python3
import cv2
import numpy as np
import depthai as dai
crop = True
fps = 30
# Create pipeline
pipeline = dai.Pipeline()
device = dai.Device()
queueNames = []
# Define sources and outputs
camRgb = pipeline.create(dai.node.Camera)
left = pipeline.create(dai.node.ColorCamera)
right = pipeline.create(dai.node.ColorCamera)
stereo = pipeline.create(dai.node.StereoDepth)
cropRgb = pipeline.create(dai.node.ImageManip)
cropLeft = pipeline.create(dai.node.ImageManip)
cropRight = pipeline.create(dai.node.ImageManip)
# Crop range
topLeft = dai.Point2f((1/6), (1/6))
bottomRight = dai.Point2f((5/6), (5/6))
cropRgb.initialConfig.setCropRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y)
cropRgb.setMaxOutputFrameSize(1280*800*3)
cropLeft.initialConfig.setCropRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y)
cropLeft.setMaxOutputFrameSize(1280*800*3)
cropRight.initialConfig.setCropRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y)
cropRight.setMaxOutputFrameSize(1280*800*3)
rgbOut = pipeline.create(dai.node.XLinkOut)
disparityOut = pipeline.create(dai.node.XLinkOut)
rgbOut.setStreamName("rgb")
queueNames.append("rgb")
disparityOut.setStreamName("depth")
queueNames.append("depth")
#Properties
rgbCamSocket = dai.CameraBoardSocket.CAM_A
camRgb.setBoardSocket(rgbCamSocket)
camRgb.setSize(1280, 800)
camRgb.setFps(fps)
# For now, RGB needs fixed focus to properly align with depth.
# This value was used during calibration
try:
calibData = device.readCalibration2()
lensPosition = calibData.getLensPosition(rgbCamSocket)
if lensPosition:
camRgb.initialControl.setManualFocus(lensPosition)
except:
raise
left.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
left.setCamera("left")
left.setFps(fps)
right.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
right.setCamera("right")
right.setFps(fps)
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
stereo.setOutputSize(1280, 800)
stereo.setLeftRightCheck(True)
stereo.setSubpixel(True)
stereo.setSubpixelFractionalBits(5)
stereo.setDepthAlign(rgbCamSocket)
if crop:
camRgb.video.link(cropRgb.inputImage)
left.isp.link(cropLeft.inputImage)
right.isp.link(cropRight.inputImage)
cropLeft.out.link(stereo.left)
cropRight.out.link(stereo.right)
cropRgb.out.link(rgbOut.input)
stereo.disparity.link(disparityOut.input)
else:
left.setIspScale(2, 3)
right.setIspScale(2, 3)
camRgb.video.link(rgbOut.input)
left.isp.link(stereo.left)
right.isp.link(stereo.right)
stereo.disparity.link(disparityOut.input)
maxDisp = stereo.initialConfig.getMaxDisparity()
with device:
device.startPipeline(pipeline)
while not device.isClosed():
queueNames = device.getQueueEvents()
for q in queueNames:
message = device.getOutputQueue(q).get()
# Display arrived frames
if type(message) == dai.ImgFrame:
frame = message.getCvFrame()
if 'depth' 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