爲了使我的問題更加清楚,請查看下面的下面的代碼:cvReleaseCapture()錯誤
抓拍圖像:
void CameraTest ::on_snapButton_clicked()
{
CvCapture* capture = cvCaptureFromCAM(0); // capture from video device #0
cvSetCaptureProperty(capture ,CV_CAP_PROP_FRAME_WIDTH , 800);
cvSetCaptureProperty(capture ,CV_CAP_PROP_FRAME_HEIGHT , 600);
if(!cvGrabFrame(capture)) //if no webcam detected or failed to capture anything
{ // capture a frame
cout << "Could not grab a frame\n\7";
exit(0);
}
IplImage* img=cvRetrieveFrame(capture); // retrieve the captured frame
cv::Mat imageContainer(img);
image=imageContainer;
cv::imshow("Mat",image);
//cvReleaseCapture(&capture); When I enable this, and run the programming calling this, there will be an error.
}
現在,程序顯示的圖像:
void CameraTest ::on_processButton_clicked()
{
cv::imshow("image snapped", image);
//my image processing steps...
}
當我啓用cvReleaseCapture(&capture)
線,我收到以下錯誤:
Unhandled exception at 0x00fc3ff5 in CameraTest.exe: 0xC0000005: Access violation reading location 0x042e1030.
當我評論/刪除行,我能夠正確後點擊另一個按鈕來顯示圖像,但是當我要拍攝的新圖像,我必須按一下按鈕幾次,這是一個重大的安全漏洞存在於程序。無論如何要繞過它嗎?
Thanks @Berak!它的工作,加上一個,併爲你接受答案。欣賞它( – rockinfresh