Hi,
I am trying to record RGB and disparity videos at the same time with an OAK-D PRO W camera. But I am having issues getting correct or complete depth values. Currently, I have the issue that I don't get depth values for distances further than approximately 2 meters.
My desired measurement distance is between 2 and 4 meters. Does someone know what the issue here could be?
- I tried setting the FOV to 127°. I'm not sure if I did that correctly.
- And I am trying to use dai.StereoDepthConfig.setDisparityShift(10) and check if that would. But it seems that I am not using it correctly.
The code I am using can be seen below.
import logging
import os
from datetime import datetime, timedelta
import cv2
import depthai as dai
import numpy as np
class Camera(object):
encode = dai.VideoEncoderProperties.Profile.H265_MAIN
fps = 30
def run(self, block=False) -> int:
logging.info("Start process to record with camera.")
# Create Pipeline
pipeline = dai.Pipeline()
# Define sources and outputs
color = pipeline.create(dai.node.ColorCamera)
color.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
color.setFps(self.fps)
color.setCamera("color")
monoLeft = pipeline.create(dai.node.MonoCamera)
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoLeft.setFps(self.fps)
monoLeft.setCamera("left")
monoRight = pipeline.create(dai.node.MonoCamera)
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoRight.setFps(self.fps)
monoRight.setCamera("right")
stereo = pipeline.create(dai.node.StereoDepth)
# stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_ACCURACY)
# stereo.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_7x7)
stereo.setLeftRightCheck(True)
stereo.setExtendedDisparity(False) # This needs to be set to False. Otherwise the number of frames differ for depth and color
stereo.setSubpixel(False)
monoLeft.out.link(stereo.left)
monoRight.out.link(stereo.right)
# Video encoder node
video_encoder_color = pipeline.create(dai.node.VideoEncoder)
video_encoder_color.setDefaultProfilePreset(self.fps, self.encode)
color.video.link(video_encoder_color.input)
# Color output node
xout_video = pipeline.create(dai.node.XLinkOut)
xout_video.setStreamName("video")
video_encoder_color.bitstream.link(xout_video.input)
# Depth output node
video_encoder_depth = pipeline.create(dai.node.VideoEncoder)
video_encoder_depth.setDefaultProfilePreset(self.fps, self.encode)
stereo.disparity.link(video_encoder_depth.input)
xout_depth = pipeline.create(dai.node.XLinkOut)
xout_depth.setStreamName("disparity")
video_encoder_depth.bitstream.link(xout_depth.input)
#dai.StereoDepthConfig.setDisparityShift(10)
with dai.Device(pipeline) as device:
logging.info(f"Camera started recording at: {datetime.now()}")
device.setIrLaserDotProjectorIntensity(1)
device.setIrFloodLightIntensity(1)
logging.info("Set camera parameters for recording with OAK camera.")
device.readCalibration().setFov(dai.CameraBoardSocket.CAM_B, 127)
device.readCalibration().setFov(dai.CameraBoardSocket.CAM_C, 127)
disparity_queue = device.getOutputQueue(name="disparity", maxSize=50, blocking=block)
video_queue = device.getOutputQueue(name="video", maxSize=50, blocking=block)
color_frame = None
disparity_frame = None
# Open a file to save encoded video
day = datetime.now().strftime("%Y%m%d")
os.makedirs(os.path.join("Videorecording", day), exist_ok=True)
with open(os.path.join("Videorecording", day, "color.mp4"), 'wb') as video_file, open(
os.path.join("Videorecording", day, "disparity.mp4"), 'wb') as depth_file:
print("Recording started...")
while True:
while disparity_queue.has():
disparity_queue.get().getData().tofile(depth_file)
while video_queue.has():
video_queue.get().getData().tofile(video_file)
if name == "main":
cam = Camera()
cam.ready = True
cam.run()