Opencv Python Raspberry Pi 无法接收帧

问题描述 投票:0回答:1

我正在使用最新的操作系统 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()

我尝试了一些事情:

  1. 我已经用 USB 网络摄像头尝试过此代码,并且运行良好。
  2. 我已使用相机模块代码更新了 /boot/config.txt 或 /boot/firmware/config.txt
    dtoverlay=ov5647
  3. 我尝试了新购买的同版本相机,只是为了确认相机或连接没有问题。
  4. 我在终端上尝试了 libcamera-hello 命令,效果很好,它打开了相机几秒钟。

但是opencv没有检测到该相机。 我尝试了另一件事,可能有助于或可能没有帮助理解这个问题:- 我尝试访问 https://webcamtests.com/ ,这里也一样,它可以检测到 USB 摄像头,但不能检测到 pi 摄像头 v1

python opencv iot raspberry-pi4 picamera
1个回答
0
投票

如果你想在bookworm上使用ov5647和cv2,你需要在

/boot/firmware/config.txt

中添加以下行
camera_auto_detect=0
start_x=1
gpu_mem=128
dtoverlay=vc4-kms-v3d

但这会使 libcamera-hello 无法使用。

但是相同的设置在 rpi5 上不起作用,我正在尝试解决它。

© www.soinside.com 2019 - 2024. All rights reserved.