Hi folks,
I'm trying to record video as part of an Open CV project. My setup is RPi4, running Trixie, and a RPi Camera Module 3 Wide, using Picamera2. to grab frames.
The Open CV recording was taken from this tutorial:
https://docs.opencv.org/4.x/dd/d43/tuto ... splay.html
Here's the code I'm using, where I've removed the frame manipulation for clarity:When run, frames are displayed correctly. The video file saved, when played back with VLC, does not play any frames, but does not give errors.
Any help appreciated.
Cheers
I'm trying to record video as part of an Open CV project. My setup is RPi4, running Trixie, and a RPi Camera Module 3 Wide, using Picamera2. to grab frames.
The Open CV recording was taken from this tutorial:
https://docs.opencv.org/4.x/dd/d43/tuto ... splay.html
Here's the code I'm using, where I've removed the frame manipulation for clarity:
Code:
# video-record-test.py Test video recordingimport cv2from picamera2 import Picamera2from libcamera import Transformimport pyautogui # Define the codec and create VideoWriter object (filename, codec, framerate, framesize)fourcc = cv2.VideoWriter_fourcc(*'XVID')out = cv2.VideoWriter('output.avi', fourcc, 20.0, (1920, 1080))# Display resolutiondisplay_width, display_height = pyautogui.size()# Initialize OpenCV windowcv2.startWindowThread()cv2.namedWindow("Camera", cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty("Camera", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) print("display_width: ", display_width, " display_height: ", display_height)# Initialize Picamera2 and configure the camerapicam2 = Picamera2()picam2.configure(picam2.create_preview_configuration(transform=Transform(hflip=True), main={"format": 'XRGB8888'}))picam2.start()while True: # Capture frame-by-frame ImageBlended = picam2.capture_array("main") # Arse about with image here # Resize the image to the screen size resized_image = cv2.resize(ImageBlended, (display_width, display_height)) # Display the resulting frame cv2.imshow("Camera", resized_image) # Save video frame out.write(resized_image) # Break the loop if 'q' is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break# Release the camera and close windowsout.release()cv2.destroyAllWindows()Any help appreciated.
Cheers
Statistics: Posted by ddwwcc — Sat Dec 20, 2025 12:27 pm — Replies 0 — Views 23