Even in simple program had a error with memory and exception. Codeblocks+mingw in debug - SIGSEGV, call stack - user32.dll. Runtime crashes with 0xc0000005 error. VC crashes too with unhandled exception.
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); //cvCaptureFromCAM( 0 );
assert( capture );
IplImage* frame=0;
cvNamedWindow("capture", CV_WINDOW_AUTOSIZE);
int counter=0;
char filename[512];
while(true){
frame = cvQueryFrame( capture );
cvShowImage("capture", frame);
char c = cvWaitKey(33);
if (c == 27) {
break;
}
}
cvReleaseCapture( &capture );
cvDestroyWindow("capture");
return 0;
}
I don't see any errors in your code. Maybe this is some libraries mistakes.
But why do you use this old OpenCV version. With C++ it's more easier
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
while(true)
{
Mat frame;
cap >> frame; // get a new frame from camera
imshow("frame", frame);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
Have you tried to exchange those following lines:
cvDestroyWindow("capture");
and
cvReleaseCapture( &capture );
I believe you should call cvDestroyWindow
before than cvReleaseCapture
. I think the window became the owner of the capture
and should be destroyed first.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.