erik thanks for your reply. I'm trying to save the frames as video, when I inspected the frame it's in 1D array and the shape keep changing. Could you please help me here?
import time
from pathlib import Path
import cv2
import depthai as dai
# Start defining a pipeline
pipeline = dai.Pipeline()
# Define a source - color camera
camRgb = pipeline.createColorCamera()
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
# Create RGB output
xoutRgb = pipeline.createXLinkOut()
xoutRgb.setStreamName("rgb")
camRgb.video.link(xoutRgb.input)
# Create encoder to produce JPEG images
videoEnc = pipeline.createVideoEncoder()
videoEnc.setDefaultProfilePreset(camRgb.getVideoSize(), camRgb.getFps(), dai.VideoEncoderProperties.Profile.MJPEG)
camRgb.video.link(videoEnc.input)
# Create JPEG output
xoutJpeg = pipeline.createXLinkOut()
xoutJpeg.setStreamName("jpeg")
videoEnc.bitstream.link(xoutJpeg.input)
# Connect and start the pipeline
with dai.Device(pipeline) as device:
# Output queue will be used to get the rgb frames from the output defined above
qRgb = device.getOutputQueue(name="rgb", maxSize=30, blocking=False)
qJpeg = device.getOutputQueue(name="jpeg", maxSize=30, blocking=True)
# Make sure the destination path is present before starting to store the examples
Path('06_data').mkdir(parents=True, exist_ok=True)
fourcc = cv2.VideoWriter_fourcc('X','V','I','D')
videoWriter = cv2.VideoWriter('test_video.avi', fourcc, 30.0, (640,480))
while True:
inRgb = qRgb.tryGet() # Non-blocking call, will return a new data that has arrived or None otherwise
if inRgb is not None:
cv2.imshow("rgb", inRgb.getCvFrame())
for encFrame in qJpeg.tryGetAll():
with open(f"06_data/{int(time.time() * 10000)}.jpeg", "wb") as f:
f.write(bytearray(encFrame.getData()))
print('type ;',type(encFrame.getData()))
print('shape ;',encFrame.getData().shape)
array = encFrame.getData()
#arr_3d = array.reshape((640,480,3))
#print('shape ;',arr_3d.shape)
#videoWriter.write(arr_3d)
if cv2.waitKey(1) == ord('q'):
break
OUTPUT:
Output exceeds the size limit. Open the full output data in a text editor
[2022-11-20 20:20:43.170] [warning] VideoEncoder setDefaultProfilePreset: passing 'width'/ 'height' is deprecated. The size is auto-determined from first frame
type ; <class 'numpy.ndarray'>
shape ; (257099,)
type ; <class 'numpy.ndarray'>
shape ; (525753,)
type ; <class 'numpy.ndarray'>
shape ; (275844,)
type ; <class 'numpy.ndarray'>
shape ; (275553,)
type ; <class 'numpy.ndarray'>
shape ; (275863,)
type ; <class 'numpy.ndarray'>
shape ; (275888,)
type ; <class 'numpy.ndarray'>
shape ; (275610,)
type ; <class 'numpy.ndarray'>
shape ; (275931,)
type ; <class 'numpy.ndarray'>
shape ; (344873,)
type ; <class 'numpy.ndarray'>
shape ; (305604,)