Hello,
I am new to OAK-D and cameras in general. I have been using the following basic script to capture RGB and depth information. However, I am facing issues recording them at high frame rates. I cannot figure out the root cause of the problem.
I am using a Cat 6 Ethernet cable directly connected to my laptop. Below are the camera specifications:
Available Camera Sensors:
{<CameraBoardSocket.CAM_C: 2>: 'OV9282', <CameraBoardSocket.CAM_A: 0>: 'OV9782', <CameraBoardSocket.CAM_B: 1>: 'OV9282'}
Product Name: OAK-D-PRO-POE-FF-97
Board Name: NG9097
I am trying to use this setup for tracking a ball. Any help or guidance would be greatly appreciated! Below is the script I am currently using:
import depthai as dai
import cv2
import os
from datetime import datetime
# Frame rate setting
FPS = 30
# Create output directory
output_dir = "oakd_recordings"
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# File paths for saving video and depth data
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
video_file = os.path.join(output_dir, f"video_{timestamp}.avi")
depth_file = os.path.join(output_dir, f"depth_{timestamp}.avi")
# Create DepthAI pipeline
pipeline = dai.Pipeline()
# Define RGB camera
cam_rgb = pipeline.create(dai.node.ColorCamera)
cam_rgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
cam_rgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_800_P)
cam_rgb.setVideoSize(1280, 800)
rgb_out = pipeline.create(dai.node.XLinkOut)
rgb_out.setStreamName("video")
cam_rgb.video.link(rgb_out.input)
# Define depth streams
mono_left = pipeline.create(dai.node.MonoCamera)
mono_right = pipeline.create(dai.node.MonoCamera)
stereo = pipeline.create(dai.node.StereoDepth)
depth_out = pipeline.create(dai.node.XLinkOut)
mono_left.setBoardSocket(dai.CameraBoardSocket.CAM_B)
mono_right.setBoardSocket(dai.CameraBoardSocket.CAM_C)
mono_left.setResolution(dai.MonoCameraProperties.SensorResolution.THE_800_P)
mono_right.setResolution(dai.MonoCameraProperties.SensorResolution.THE_800_P)
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_ACCURACY)
stereo.setDepthAlign(dai.CameraBoardSocket.CAM_A)
stereo.setSubpixel(True) # Improves depth accuracy
stereo.setLeftRightCheck(True)
stereo.setRectifyEdgeFillColor(0) # Fills invalid depth with interpolated values
mono_left.out.link(stereo.left)
mono_right.out.link(stereo.right)
stereo.depth.link(depth_out.input)
depth_out.setStreamName("depth")
# Set frame rates
cam_rgb.setFps(FPS)
mono_left.setFps(FPS)
mono_right.setFps(FPS)
# Start the pipeline
with dai.Device(pipeline) as device:
# Get video and depth queues
video_queue = device.getOutputQueue(name="video", maxSize=8, blocking=False)
depth_queue = device.getOutputQueue(name="depth", maxSize=8, blocking=False)
device.setIrLaserDotProjectorBrightness(1200)
device.setIrFloodLightBrightness(800)
# Setup OpenCV video writers
video_writer = cv2.VideoWriter(video_file, cv2.VideoWriter_fourcc(\*'XVID'), FPS, (1280, 800))
depth_writer = cv2.VideoWriter(depth_file, cv2.VideoWriter_fourcc(\*'XVID'), FPS, (1280, 800), isColor=False)
print("Recording started. Press 'q' to stop.")
start_time = datetime.now()
while True:
# Read and display RGB video frame
video_frame = video_queue.get()
video_data = video_frame.getCvFrame()
video_writer.write(video_data)
cv2.imshow("RGB Video", video_data)
# Read and display depth frame
depth_frame = depth_queue.get()
depth_data = depth_frame.getFrame() # 16-bit raw depth data (in mm)
depth_writer.write(depth_data)
# Normalize depth data for visualization
depth_vis = cv2.normalize(depth_data, None