【问题标题】:Unable to open webcam video on raspberry pi 4无法在树莓派 4 上打开网络摄像头视频
【发布时间】:2021-08-11 13:22:09
【问题描述】:

我正在尝试使用 OpenCV 4 在我的树莓派 4 上打开一个用于视频流的网络摄像头。

OpenCV 中的VideoCapture 构造函数获取设备位置的索引/地址。使用 'lsusb' 我得到了这个:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:08c5 Logitech, Inc. QuickCam Pro 5000
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

这里没有太多关于地址的帮助。所以绑定`usb-devices':

[26020.467167] usb 1-1.3: new high-speed USB device number 4 using xhci_hcd
[26020.769321] usb 1-1.3: New USB device found, idVendor=046d, idProduct=08c5, bcdDevice= 0.05
[26020.769346] usb 1-1.3: New USB device strings: Mfr=0, Product=0, SerialNumber=2
[26020.769365] usb 1-1.3: SerialNumber: 02B5FC83
[26020.771874] uvcvideo: Found UVC 1.00 device <unnamed> (046d:08c5)
[26021.026615] input: UVC Camera (046d:08c5) as /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.3/1-1.3:1.0/input/input1
[26021.091092] usb 1-1.3: Warning! Unlikely big volume range (=3072), cval->res is probably wrong.

我试过了:046d:08c5/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.3/1-1.3:1.0/input/input1,但都没有成功。

我应该寻找另一种打开相机的方法吗?

这是代码(几乎是从 opencv 网站上提取的示例):

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    //Open the default video camera
    VideoCapture cap("046d:08c5");

    // if not success, exit program
    if (cap.isOpened() == false)
    {
        cout << "Cannot open the video camera" << endl;
        cin.get(); //wait for any key press
        return -1;
    }

    double dWidth = cap.get(CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

    cout << "Resolution of the video : " << dWidth << " x " << dHeight << endl;

    string window_name = "My Camera Feed";
    namedWindow(window_name); //create a window called "My Camera Feed"

    while (true)
    {
        Mat frame;
        bool bSuccess = cap.read(frame); // read a new frame from video 

        //Breaking the while loop if the frames cannot be captured
        if (bSuccess == false)
        {
            cout << "Video camera is disconnected" << endl;
            cin.get(); //Wait for any key press
            break;
        }

        //show the frame in the created window
        imshow(window_name, frame);

        //wait for for 10 ms until any key is pressed.  
        //If the 'Esc' key is pressed, break the while loop.
        //If the any other key is pressed, continue the loop 
        //If any key is not pressed withing 10 ms, continue the loop 
        if (waitKey(10) == 27)
        {
            cout << "Esc key is pressed by user. Stoppig the video" << endl;
            break;
        }
    }

    return 0;

}

【问题讨论】:

标签: c++ opencv raspberry-pi raspberry-pi4


【解决方案1】:

通过安装v4l2-ctl解决:https://askubuntu.com/a/848390/918858

VideoCapture 构造函数还接受一个可以引用/dev/video*const string&amp;(VideoCapture (const String &filename))。 v4l2-ctl 包为您提供/dev/ 映射。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 2013-01-01
    • 2017-05-12
    • 2017-09-25
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多