OpenCV Webcam
Hi friends, I am using my webcam for the opencv project. I have tested the webcam with both java and c++. It is working for the Java, but not for C++. Its difficult to find out what was the problem. I am very much certain that, there is no problem in the C++ codes. When I google it, some people says that opencv supports for only specific types of cameras. But still its working for the java opencv, then what is the issue with the C++ ?
Can anyone give me the actual reason behind this and how to solve this problem?
This is the code I tried in C++. Here the webcam indicator light getting on. But the webcam window is gray coloured.
include "stdafx.h"
include "cv.h"
include "highgui.h"
include <stdio.h>
int main() { CvCapture* capture = cvCaptureFromCAM(-1);
if( !capture ) { fprintf( stderr, "ERROR: capture is NULL \n" ); getchar(); return -1; }
cvNamedWindow( "Mycapture", CV_WINDOW_AUTOSIZE );
while( 1 ) {
cvGrabFrame(capture); IplImage* frame = cvRetrieveFrame(capture);
if( !frame ) { fprintf( stderr, "ERROR: frame is null...\n" ); getchar(); break; } cvShowImage( "Mycapture", frame );
if( (cvWaitKey(10) & 255) == 27 ) break; }
cvReleaseCapture( &capture ); cvDestroyWindow( "Mycapture" );
return 0; }
I've used the Visual C++. And my webcam is HP TrueVision webcam.
Thanks in advance...
Can you specify you system, opencv compilation flags, source code, camera model and error?
This is the code I tried in C++. Here the webcam indicator light getting on. But the webcam window is gray coloured.
include "stdafx.h" include "cv.h" include "highgui.h" include <stdio.h>
int main() { CvCapture* capture = cvCaptureFromCAM(-1);
if( !capture ) { fprintf( stderr, "ERROR: capture is NULL \n" ); getchar(); return -1; }
cvNamedWindow( "Mycapture", CV_WINDOW_AUTOSIZE );
while( 1 ) {
cvGrabFrame(capture); IplImage* frame = cvRetrieveFrame(capture);
if( !frame ) { fprintf( stderr, "ERROR: frame is null...\n" ); getchar(); break; } cvShowImage( "Mycapture", frame );
if( (cvWaitKey(10) & 255) == 27 ) break; }
cvReleaseCapture( &capture ); cvDestroyWindow( "Mycapture" );
return 0; }
I've used the Visual C++. And my webcam is HP TrueVision webcam.
Just a hunch but could you be specifying the wrong camera id? I see it is a -1. I am new to opencv and am using it on Linux but my camera id is not negative.
Which version of OpenCV you are using? You code works fine on Linux 3.5.7-gentoo with OpenCV 2.4.5
Victor: I am using opencv 2.2 on Windows 7.
Pranav Lal: Camera id is not a problem. Because my webcam indicator is getting on. So webcam is working. But the window is gray coloured.
I have installed the opencv 2.45. Now everything fine. Thanks for your suggestions.