Unable to open webcam video on raspberry pi 4

  c++, opencv, raspberry-pi, raspberry-pi4

I am trying to open a webcam for video streaming on my raspberry pi 4 with OpenCV 4.

The VideoCapture constructor in OpenCV takes the index/address of the location of the device. Using ‘lsusb’ I get this:

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

Not much help here regarding address. So tying `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.

I tried: 046d:08c5 and /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 but neither worked.

Is there an alternative way I should be looking at to open the camera?

Here’s the code (pretty much pulled example off the opencv website):

#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;

}

Source: Windows Questions C++

LEAVE A COMMENT