I am working on Raspberry Pi 4 with the latest os VERSION="12 bookworm" and a Raspberry Pi camera Rev1.3. I want to use this pi camera to capture video useing opencv.
Issue: I getting error that Can't receive frame or in other words it can't access pi camera.It works fine with USB webcam but not with pi camera.
Here is the sample code:
import numpy as np
import cv2 as cv
cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) == ord('q'):
break
# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
I have tried a few things:
- I have tried this code with USB webcam and it workes fine with it.
- I have updated /boot/config.txt or /boot/firmware/config.txt with the camera module code
dtoverlay=ov5647 - I have tried a new purchased camera of same version just to confirm that there is no issue in camera or connection.
- I have tried libcamera-hello command on terminal that works fine, it opens up camera for a few seconds.
But this camera is not detected with the opencv. I have tried one other thing that might or might not helpfull to undestand the issue:- I tried to wisit https://webcamtests.com/ and same here it can detect USB camera but not the pi camera v1