无法在 raspberry pi 4 上打开网络摄像头视频

Unable to open webcam video on raspberry pi 4

我正在尝试使用 OpenCV 4 在我的 raspberry pi 4 上打开网络摄像头进行视频流传输。

OpenCV 中的VideoCapture 构造函数获取设备位置的index/address。使用 '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;

}

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

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