I would like to read a video stream from an oak-d pro poe camera and write a video file with at least 20 fps. I can only get about 3 fps from the color camera, so now I'm trying 640x400 resolution from one of the mono cameras. I am able to get about 15 fps here, but the video file I am creating is corrupt. So, my question is - how can I get 20 fps video and write it into a video file?
Here is my cobbled-together code:
#!/usr/bin/env python3
import cv2
import depthai as dai
import time
# Create pipeline
pipeline = dai.Pipeline()
device_info = dai.DeviceInfo("192.168.70.86")
# Define sources and outputs
monoLeft = pipeline.create(dai.node.MonoCamera)
monoRight = pipeline.create(dai.node.MonoCamera)
xoutLeft = pipeline.create(dai.node.XLinkOut)
xoutRight = pipeline.create(dai.node.XLinkOut)
xoutLeft.setStreamName('left')
xoutRight.setStreamName('right')
# Properties
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
desired_fps = 20 # Change this value to your desired fps
monoLeft.setFps(200)
monoRight.setFps(200)
# Linking
monoRight.out.link(xoutRight.input)
monoLeft.out.link(xoutLeft.input)
# Connect to device and start pipeline
with dai.Device(pipeline, device_info) as device:
# Output queues will be used to get the grayscale frames from the outputs defined above
qLeft = device.getOutputQueue(name="left", maxSize=4, blocking=False)
qRight = device.getOutputQueue(name="right", maxSize=4, blocking=False)
startTime = time.monotonic()
counter = 0
fps = 0
while True:
# Instead of get (blocking), we use tryGet (non-blocking) which will return the available data or None otherwise
inLeft = qLeft.get()
#inRight = qRight.get()
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('C:\CPI\outputmono.avi', fourcc, 20, (640, 400))
cv2.imshow("left", inLeft.getCvFrame())
#cv2.imshow("right", inRight.getCvFrame())
in_video = qLeft.get()
frame = in_video.getCvFrame()
out.write(frame)
if cv2.waitKey(1) == ord('q'):
break
# Release the VideoWriter object
out.release()
#counter+=1
#current_time = time.monotonic()
#if (current_time - startTime) > 1 :
# fps = counter / (current_time - startTime)
# counter = 0
# startTime = current_time
# print(f"FPS={fps:.2f}")
Thanks for any help.