I have trouble with accessing webcam using opencv 2.4.3.
My System:
Hp Probook 4530s - HP Fixed HD Webcam
Ubuntu 12.10
OpenCV 2.4.3
İf I want to capture my built-in camera i get ERROR: capture is NULL
I'm using http://opencv.willowgarage.com/wiki/CameraCapture sample code.
Sample code is:
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
// A Simple Camera Capture Framework
int main() {
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if ( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
// Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
while ( 1 ) {
// Get one frame
IplImage* frame = cvQueryFrame( capture );
if ( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "mywindow", frame );
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
I also tried with xawtv -hwscan using typing terminal. I get this output:
looking for available devices
port 129-144
type : Xvideo, image scaler
name : Intel(R) Textured Video`
/dev/video0: OK
[ -device /dev/video0 ]
type : libv4l
name : HP HD Webcam [Fixed]
flags: capture
then I can access my webcam typing xawtv video0. I think I have no trouble with my webcam. I have trouble with opencv.
I solved my problem few minutes ago. And I decided share my solution for people who handling similar error.
First I didnt install some of below packets ( I dont remember which of them, so I paste all of them)
libjpeg62-dev
libtiff4-dev
zlib1g-dev
libjasper-dev
libavcodec-dev
libdc1394-22-dev
libgstreamer0.10-dev
libgstreamer-plugins-base0.10-dev
libavformat-dev
libv4l-dev
libswscale-dev
Then You should configure your cmake process with this code
cmake -D CMAKE_BULD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON USE_V4L=ON WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON USE_GStreamer=ON ..
Please notice USE_V4L=ON this code..
I hope you solve after reading my solution.