在OpenCV面部检测应用程序中抛出SEHException

时间:2012-10-11 04:09:32

标签: opencv

我创建了一个OpenCV的简单Windows窗体应用程序,它捕获来自网络摄像头的图像流并检测面部,然后将图像显示到图片框。我创建了一个单独的线程来执行面部检测器功能。表单有一个按钮和图片框,当按下按钮时,面部检测器线程启动。它工作正常大约2分半钟,然后抛出这个异常:

An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in Sampleapp.exe

Additional information: External component has thrown an exception.

以下是面部检测器功能的完整代码:

#include "stdafx.h"
#include "Form1.h"
#include <cv.h>
#include <highgui.h>

namespace Sampleapp {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    const char *frontalface_cascade_name = "haarcascade_frontalface_alt.xml";
    CvHaarClassifierCascade *frontalface_cascade;
    //----------------------
    // Face detector
    void Form1::face_detector()
    {
        IplImage* img;
        IplImage *img_gray;
        CvMemStorage *storage;
        CvSeq* faces;
        /*CvSeq* righteye;
        CvSeq* lefteye;
        CvSeq* nose;*/
        frontalface_cascade = ( CvHaarClassifierCascade* )cvLoad( frontalface_cascade_name, 0, 0, 0 );
        while(this->button1->Text == "no")
        {
            try             
            {
                storage = cvCreateMemStorage( 0 );
                CvCapture *capture = cvCreateCameraCapture(0);
                img = cvQueryFrame(capture);
                img_gray = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
                cvCvtColor( img, img_gray, CV_BGR2GRAY );
                cvEqualizeHist( img_gray, img_gray );
                faces = cvHaarDetectObjects( img_gray, frontalface_cascade, storage, 1.1, 2, CV_HAAR_FIND_BIGGEST_OBJECT, cvSize(40, 40));
                this->pictureBox1->Image = (gcnew System::Drawing::Bitmap(img->width,img->height,img->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)img->imageData));                            
                cvReleaseMemStorage(&storage);
            }
            catch (System::NullReferenceException^ m)
            {
            }
        }
    }
}

抛出异常:

faces = cvHaarDetectObjects( .....)

段。

这是Debug输出:

First-chance exception at 0x74b9c41f in Sampleapp.exe: Microsoft C++ exception: cv::Exception at memory location 0x069ce950.. 
A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in Sampleapp.exe 
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in Sampleapp.exe 
Additional information: External component has thrown an exception.

如果有人知道我应该怎么做才能解决这个问题,请告诉我。

此致Josiah

0 个答案:

没有答案