jakaskerl
Thanks for the help, sorry for the slow response 🙂
I did what you suggested but now I'm getting the following error:
Left input image stride ('3840') should be equal to its width ('1280'). Skipping frame!
Code:
#!/usr/bin/env python3
from collections import deque
import cv2
import numpy as np
import depthai as dai
import time
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)
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)
camRgb.setPreviewSize(1280, 800)
# 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)
left.setPreviewSize(1280, 800)
right.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
right.setCamera("right")
right.setFps(fps)
right.setPreviewSize(1280, 800)
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
stereo.setOutputSize(1280, 800)
stereo.setLeftRightCheck(True)
stereo.setSubpixel(True)
stereo.setSubpixelFractionalBits(5)
stereo.setDepthAlign(rgbCamSocket)
camRgb.preview.link(rgbOut.input)
left.preview.link(stereo.left)
right.preview.link(stereo.right)
stereo.disparity.link(disparityOut.input)
maxDisp = stereo.initialConfig.getMaxDisparity()
prev_frame_time = 0
new_frame_time = 0
average_fps = deque(maxlen=30)
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:
new_frame_time = time.time()
average_fps.append(1/(new_frame_time-prev_frame_time))
prev_frame_time = new_frame_time
cv2.putText(frame, str(np.mean(average_fps)), (7, 70), cv2.FONT_HERSHEY_SIMPLEX , 3, (100, 255, 0), 3, cv2.LINE_AA)
cv2.imshow(q, frame)
if cv2.waitKey(1) == ord('q'):
break