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>
// A Simple Camera Capture Framework
int main()
{
CvCapture* capture = cvCaptureFromCAM(-1);
if( !capture )
{
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
} // Create a window in which the captured images will be presented
cvNamedWindow( "Mycapture", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
);
while( 1 )
{
// Get one frame
{
cvGrabFrame(capture);
IplImage* frame = cvRetrieveFrame(capture);
//IplImage* frame = cvQueryFrame(capture);
cvRetrieveFrame(capture);
if( !frame )
{
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "Mycapture", 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( "Mycapture" );
////free(capture);
);
return 0;
}
I've used the Visual C++. And my webcam is HP TrueVision webcam.
webcam.
Thanks in advance...