Ask Your Question

Camera is not working in OpenCV on Ubuntu 12.04 with version 2.3.1 or 2.4.2

asked 2012-08-08 15:41:04 -0600

xamox gravatar image

I have tried to build the example but am getting a NULL when trying to capture the device.

Feel free to grab my code here at test for yourself:

The camera works fine as I'm able to use it with Cheese, Guvcview. I have tested a lot of variations to the cvCaptureFromCAM( CV_CAP_ANY ), as in 0,1,2,-1, etc. I also tried using the VideoCapture function, but doesn't appear to be working.

I'm not sure what I need to do to get it working. I've tried building OpenCV 2.3.1 and 2.4.2 from source, everything builds fine, I can import in python, just can't seem to get the webcam to work. I have also tested a few external logitech webcams I have laying around. Any help would be appreciated.

edit retag flag offensive close merge delete


Exactly the same problem I am facing- Cheese and Skype are able to recognize the camera but the sample code is not.

VedMathai gravatar imageVedMathai ( 2013-01-22 09:50:39 -0600 )edit

3 answers

Sort by » oldest newest most voted

answered 2012-11-02 18:00:25 -0600

blackgk gravatar image

updated 2012-11-03 08:49:11 -0600

sammy gravatar image

Try to install some/all packages from:

"(Optional) ffmpeg, libgstreamer, libv4l, libxine, unicap, libdc1394 2.x.

You should have some/all of these packages installed (together with associated development packages) to add video capturing, video decoding and video encoding capabilities to highgui. The output of the cmake will show you, which of the packages have been detected and will be used in highgui. (Enable full video support with FFMPEG). For example, on Ubuntu 9.10 all the necessary ffmpeg files can be installed using the following command:

     sudo apt-get install libavformat-dev libswscale-dev"

And after installing it, remember to rebuild OpenCV. I have the same problem.

edit flag offensive delete link more

answered 2012-08-09 11:49:26 -0600

xamox gravatar image

Okay, this appears to be working with OpenCV 2.4.2. Not sure what I was doing differently before, verified for 2.3 I run:

sudo make uninstall

before 2.4 running:

sudo make install

So maybe something was cached, or I had never completely removed 2.3 before, which still is not working but 2.4 is, which is fine.

edit flag offensive delete link more

answered 2012-08-08 20:16:26 -0600

Tõnu Samuel gravatar image

Sounds like your camera device /dev/video0 is inaccessible to non-root users. Try to run with sudo.

edit flag offensive delete link more


Alas, I got quite excited as I thought this may fix it, but still getting NULL when trying to capture even with sudo.

xamox gravatar imagexamox ( 2012-08-09 10:40:45 -0600 )edit

Question Tools


Asked: 2012-08-08 15:41:04 -0600

Seen: 7,586 times

Last updated: Nov 03 '12