-2
我是opencv的新手,并且编写了一个非常简单的程序来显示从摄像头捕获的图像。在一个简单的opencv摄像头程序中抛出异常
的代码是:
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv) {
cvNamedWindow("win");
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame = cvQueryFrame(capture);
IplImage* out = cvCreateImage(cvGetSize(frame), frame->depth, 1);
while(1) {
frame = cvQueryFrame(capture);
if(!frame) break;
cvCanny(frame, out, 10, 100, 30);
cvShowImage("win", out); // !!!!! this line thrown exception
char c = cvWaitKey(20);
if(c==27) break;
}
cvReleaseImage(&out);
cvReleaseCapture(&capture);
cvDestroyWindow("win");
return 0;
}
但是当我运行它,它会抛出异常:
Unhandled exception at at 0x000007FEFDD0CACD in Project2.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000024DA50.
哪里是错误的,如何解决呢?
更新
最后,我找到了原因:
cvCanny(frame, out, 10, 100, 30);
最后一个参数是太大了,如果我将其更改为3
,一切工作正常。
在调试器中运行,看看实际发生了什么。 – Axel 2012-08-06 07:49:11