Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV not initializing USB camera

Tags:

c++

opencv

video

I am trying to capture video from a USB camera using OpenCV.

#include <highgui.h>
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    VideoCapture cap (-1);
    if (!cap.isOpened())
         cout << "Cam initialize failed";
    else cout << "Cam initialized";

    return 0;
}

It is failing to initialize the camera. cap.isOpened() is returning zero.

The same program, with same version of OpenCV and the same USB camera, is correctly running in my friend's machine. I am running Fedora 16. The camera is properly working in another application (for example, Cheese).

I did some searching in Google and Stack Overflow. But no useful help. Any idea?

like image 718
Barshan Das Avatar asked Nov 12 '22 20:11

Barshan Das


1 Answers

Try running your program as root. You may not have permission, and opencv doesn't tell you if thats the reason cap.isOpened() failed.

like image 126
dmagree Avatar answered Nov 15 '22 12:11

dmagree