-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