应用程序在读取35-40个摄像头帧后崩溃
Application crashes after reading 35-40 Webcam frames
我已经成功地检测了从网络摄像头捕获的人脸,但是在捕获了大约35-40帧之后,应用程序崩溃了,我只发布了我代码的相关部分,_Image
是我实现的一个类。
_Image *Obj;
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if ( !capture )
{
fprintf( stderr, "nn---ERROR: capture is NULL---n" );
}
IplImage * frame = cvQueryFrame( capture );
// Show the image captured from the camera in the window and repeat
while (1)
{
frame = cvQueryFrame( capture );
if ( !frame ) {
fprintf( stderr, "ERROR: Webcam frame is null...Unexpected Error - Exiting" );
getchar();
exit(0);
}
Obj = new _Image(frame);
if(Obj==0)
{
fprintf( stderr, "nERROR: Out of Memory!!n" );
cvReleaseImage(&frame );
cvDestroyAllWindows();
// Release the capture device
cvReleaseCapture( &capture );
exit(0);
}
flag = Obj->detect_face_in_image();
if(flag!=0)
{
Obj->add_frame_name();
Obj->webcam_reader( *Obj);
}
// Do not release the frame!
delete Obj;
cvNamedWindow( "WEBCAM", CV_WINDOW_AUTOSIZE );
cvShowImage ( "WEBCAM", frame);
if ( (cvWaitKey(10)) == 27 )
{
cvReleaseImage(&frame );
cvDestroyAllWindows();
// Release the capture device
cvReleaseCapture( &capture );
break;
}
}
然而,我没有得到这种崩溃,如果我改变我的代码一点播放AVI文件,这只发生在网络摄像头。我得到Windows XP send or dont send error report
,崩溃前没有特定的错误信息
只要代码不完整,就不可能给出原因。
你正在传递*Obj到Obj->webcam_reader() -为什么,如果Obj已经作为this指针传递了。
根据webcam_reader是如何定义的,你可以在此时复制Obj(如果你不通过引用传递)。如果不能安全地复制该对象,您可能会遇到问题。如果您没有实现复制构造函数,而是在该类中使用手动分配的动态内存,则可能会出现这种情况。在这种情况下,只有一个指针被复制和释放两次。
如上所述,人们只能猜测原因。
change
cvWaitKey(10);
cvWaitKey(25);
或者
cvWaitKey(35);
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- 程序崩溃并显示"std::out_of_range"错误
- CoInitialize()在单独的线程上崩溃而不返回
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么所有C++编译器都会崩溃或挂起此代码
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 为什么我的多线程作业队列崩溃
- ExtractIconEx:可以工作,但偶尔会崩溃
- 为什么引用传递会导致此崩溃(C++)
- 试图创建流或fopen时程序崩溃
- 类对象数组的问题会导致崩溃
- 排序时无法执行交换操作.我做的时候它会崩溃.为什么
- 为什么要增加导致崩溃的指针
- 在虚幻引擎中删除NXOpen对象时崩溃
- 为什么它只打印双链接列表的第一个值,而我的程序却崩溃了
- OpenCV在imShow上崩溃仅适用于USB网络摄像头
- 尝试捕获默认 iSight 摄像头时出现 OpenCV 崩溃
- 应用程序在读取35-40个摄像头帧后崩溃