Ask Your Question
0

OpenCV Webcam

asked 2013-06-15 21:47:43 -0600

Krishnananthan gravatar image

updated 2013-06-16 06:22:12 -0600

AMP gravatar image

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...

edit retag flag offensive close merge delete

Comments

Can you specify you system, opencv compilation flags, source code, camera model and error?

Victor1234 gravatar imageVictor1234 ( 2013-06-16 03:13:51 -0600 )edit

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.

Krishnananthan gravatar imageKrishnananthan ( 2013-06-16 06:19:33 -0600 )edit

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.

Pranav Lal gravatar imagePranav Lal ( 2013-06-16 11:08:13 -0600 )edit

Which version of OpenCV you are using? You code works fine on Linux 3.5.7-gentoo with OpenCV 2.4.5

Victor1234 gravatar imageVictor1234 ( 2013-06-17 04:03:46 -0600 )edit

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.

Krishnananthan gravatar imageKrishnananthan ( 2013-06-17 07:01:43 -0600 )edit

I have installed the opencv 2.45. Now everything fine. Thanks for your suggestions.

Krishnananthan gravatar imageKrishnananthan ( 2013-06-17 09:47:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-06-16 11:08:01 -0600

Hi, I used to have the same problem earlier as I was using OpnnCV 2.2 with C++ but now I have upgraded to newer OpenCV version and the problem has been solved.

As per me,the problem is with the functionalities supported by the earlier version of OpenCV is the cause for this problem . Try this and see if it helps you .

edit flag offensive delete link more

Comments

Thanks mate. It worked. Thank you very much..

Krishnananthan gravatar imageKrishnananthan ( 2013-06-17 09:46:22 -0600 )edit

Question Tools

Stats

Asked: 2013-06-15 21:47:43 -0600

Seen: 3,919 times

Last updated: Jun 16 '13