I have installed VS2008 and am able to run the demo codes "camshiftdemo and lkdemo " which comes in the opencv library. With this done, now I am trying to run some simple codes from the internet to get acquainted with the OpenCV. I am just trying to display video from webcam and I am getting the following error..
Error I am getting is :
Unhandled exception at 0x5e7e3d10 (highgui200.dll) in opencv.exe: 0xC00000开发者_Go百科05: Access violation reading location 0x719b3856.
The code I am trying to run is :
#include <cv.h>
#include <highgui.h>
void main(int argc,char *argv[])
{
int c;
IplImage* color_img;
CvCapture* cv_cap = cvCaptureFromCAM(-1); // -1 = only one cam or doesn't matter
cvNamedWindow("Video",1); // create window
for(;;) {
color_img = cvQueryFrame(cv_cap); // get frame
if(color_img != 0)
cvShowImage("Video", color_img); // show frame
c = cvWaitKey(10); // wait 10 ms or for key stroke
if(c == 27)
break; // if ESC, break and quit
}
/* clean up */
cvReleaseCapture( &cv_cap );
cvDestroyWindow("Video");
}
Any help in this will be greatly appreciated.
The following code compiles and works for me in VS2008 using OpenCV 2.1
#include <cv.h>
#include <highgui.h>
void main(int argc,char *argv[])
{
int c;
IplImage* color_img;
CvCapture* cv_cap = cvCaptureFromCAM(0);
cvNamedWindow("Video",0); // create window
for(;;) {
color_img = cvQueryFrame(cv_cap); // get frame
if(color_img != 0)
cvShowImage("Video", color_img); // show frame
c = cvWaitKey(10); // wait 10 ms or for key stroke
if(c == 27)
break; // if ESC, break and quit
}
/* clean up */
cvReleaseCapture( &cv_cap );
cvDestroyWindow("Video");
}
I think you must delete the "cvReleaseCapture( &cv_cap );" sentence. I tried it. It can be work. Somehow, when you hit the ESC button, the capture is being released. It's worth to try.
精彩评论