Luxonis-Alex
Yeah, 50-55 FPS could be OK.
With this code to create the UVC camera:
import time
import depthai as dai
def getPipeline():
enable_4k = False # Will downscale 4K -> 1080p
pipeline = dai.Pipeline()
# Define sources - two mono cameras
camB = pipeline.create(dai.node.ColorCamera)
camC = pipeline.create(dai.node.ColorCamera)
# Set properties for camera B
camB.setBoardSocket(dai.CameraBoardSocket.CAM_B)
camB.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
# Set properties for camera C
camC.setBoardSocket(dai.CameraBoardSocket.CAM_C)
camC.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1200_P)
# Create an UVC (USB Video Class) output node
uvc = pipeline.createUVC()
camB.isp.link(uvc.input)
camC.isp.link(uvc.input)
# Note: if the pipeline is sent later to device (using startPipeline()),
# it is important to pass the device config separately when creating the device
config = dai.Device.Config()
# config.board.uvc = dai.BoardConfig.UVC() # enable default 1920x1080 NV12
config.board.uvc = dai.BoardConfig.UVC(1920, 1200)
config.board.uvc.frameType = dai.ImgFrame.Type.YUV420p
# config.board.uvc.cameraName = "My Custom Cam"
pipeline.setBoardConfig(config.board)
return pipeline
# Standard UVC load with depthai
with dai.Device(getPipeline()) as device:
print("\nDevice started, please keep this process running")
print("and open an UVC viewer to check the camera stream.")
print("\nTo close: Ctrl+C")
# Doing nothing here, just keeping the host feeding the watchdog
while True:
try:
continue
except KeyboardInterrupt:
break
And this one to record videos:
import cv2
import os
from datetime import datetime
# Set up the video capture object to capture video from the first camera device
cap = cv2.VideoCapture(0)
# Check if the camera opened successfully
if not cap.isOpened():
print("Error: Could not open video device.")
exit()
# Set the properties for capture
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1200)
cap.set(cv2.CAP_PROP_FPS, 60)
# Create a folder to save the frames
folder_name = 'Captured_Frames'
os.makedirs(folder_name, exist_ok=True)
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Use 'mp4v' for MP4 format
out = cv2.VideoWriter('output.mp4', fourcc, 60.0, (1920, 1200))
# Capture frames in a loop
frame_count = 0
while True:
ret, frame = cap.read()
if not ret:
print("Error: No frame has been captured.")
break
# Save each frame to the specified folder
#timestamp = datetime.now().strftime('%Y%m%d_%H%M%S%f')
frame_filename = os.path.join(folder_name, f'frame_{frame_count}.jpg')
cv2.imwrite(frame_filename, frame)
frame_count += 1
out.write(frame)
# Display the resulting frame
cv2.imshow('frame', frame)
# Press 'q' on the keyboard to exit the loop
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture object
# When everything is done, release the capture and writer objects
cap.release()
out.release()
cv2.destroyAllWindows()
Recording a chronometer at 30 FPS I cant find two frames with the same time, its seems that only arrives one of the two frames for each time.
Would be really helpful for my project if you can achieve the UVC approach with metadata to synchronize frames.
Thank you so much for your help.