我正在使用最新的操作系统 VERSION="12 bookworm" 和 Raspberry Pi 相机 Rev1.3 开发 Raspberry Pi 4。 我想用这个 pi 相机使用 opencv 捕获视频。
问题:我收到错误消息无法接收帧,或者换句话说,它无法访问 pi 相机。它可以与 USB 网络摄像头配合使用,但不能与 pi 相机配合使用。
这是示例代码:
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()
我尝试了一些事情:
dtoverlay=ov5647
但是opencv没有检测到该相机。 我尝试了另一件事,可能有助于或可能没有帮助理解这个问题:- 我尝试访问 https://webcamtests.com/ ,这里也一样,它可以检测到 USB 摄像头,但不能检测到 pi 摄像头 v1
如果你想在bookworm上使用ov5647和cv2,你需要在
/boot/firmware/config.txt
中添加以下行
camera_auto_detect=0
start_x=1
gpu_mem=128
dtoverlay=vc4-kms-v3d
但这会使 libcamera-hello 无法使用。
但是相同的设置在 rpi5 上不起作用,我正在尝试解决它。