即使在简单程序中也存在内存和异常错误。调试中的代码块+ mingw - SIGSEGV,调用堆栈 - user32.dll。运行时崩溃,出现0xc0000005错误。 VC也因未处理的异常而崩溃。
#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;
}
答案 0 :(得分:1)
我在您的代码中看不到任何错误。也许这是一些库错误。
但是为什么要使用这个旧的OpenCV版本。 使用C ++更容易
#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;
}
答案 1 :(得分:0)
您是否尝试过以下几行:
cvDestroyWindow("capture");
和
cvReleaseCapture( &capture );
我相信你应该在cvDestroyWindow
之前致电cvReleaseCapture
。我认为窗口成了capture
的所有者,应该首先销毁。