Thanks you so much! this helps narrow the problem down a lot!
I am establishing an ssh using mobaXterm on a window pc. X11-Forwarding is enabled in mobaXterm as well as in /etc/ssh/sshd_config on the pi side. I cant seem to find much regarding enabling software rendering.
rpicam-hello --qt-preview does stream the camera for a few seconds!
Eventually I wanted to be able to acces the camera through a python script like below.
Running this script results in an error however, because Bookworm does not seem to support the opencv function Videocapture().
Running the code below from a similar topic by bluePiuser (viewtopic.php?t=371869) works for me in case anyone else got a similar issue!
I am establishing an ssh using mobaXterm on a window pc. X11-Forwarding is enabled in mobaXterm as well as in /etc/ssh/sshd_config on the pi side. I cant seem to find much regarding enabling software rendering.
rpicam-hello --qt-preview does stream the camera for a few seconds!
Eventually I wanted to be able to acces the camera through a python script like below.
Code:
import cv2import time# Initialize the video capture (default camera, typically index 0)cap = cv2.VideoCapture(0)# Check if the camera opened successfullyif not cap.isOpened(): print("Error: Could not open the camera.") exit()# Define the codec and create VideoWriter objectfourcc = cv2.VideoWriter_fourcc(*'XVID')out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480)) # 20 FPS, resolution 640x480# Record video for 2 secondsstart_time = time.time()while time.time() - start_time < 2: ret, frame = cap.read() if not ret: print("Error: Failed to capture frame.") break # Write the frame to the output file out.write(frame) # Optionally display the recording window cv2.imshow('Recording', frame) # Exit if 'q' is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break# Release resourcescap.release()out.release()cv2.destroyAllWindows()print("Video recording saved as 'output.avi'")Code:
WARN:0@0.122] global ./modules/videoio/src/cap_gstreamer.cpp (2401) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Failed to allocate required memory.[ WARN:0@0.122] global ./modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline[ WARN:0@0.122] global ./modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been createdError: Failed to capture frame.Code:
from picamera2 import Picamera2, Previewimport cv2import numpy as np# Initialize Picamera2picam2 = Picamera2()# Configure Picamera2camera_config = picam2.create_still_configuration(main={"size": (640, 480)})picam2.configure(camera_config)# Start the camerapicam2.start()# Create a window to display the videocv2.namedWindow("Picamera2 OpenCV Example", cv2.WINDOW_AUTOSIZE)while True: # Capture image frame = picam2.capture_array() # Convert to grayscale gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the frame cv2.imshow("Picamera2 OpenCV Example", gray_frame) # Break the loop on 'q' key press if cv2.waitKey(1) & 0xFF == ord('q'): break# Release resourcescv2.destroyAllWindows()picam2.stop()Statistics: Posted by S98Arne — Thu Jan 23, 2025 12:30 pm