Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::Exception at memory location in MFC

I am using MFC to write GUI that allows to display video from webcam using opencv 2.4.10. However, I have a error that recorded in youtube.I using thread to show video. I used a thread to open and detect video.The thread is defined as

UINT CDialogResizeDlg::StartThread (LPVOID param)
{
    THREADSTRUCT*    ts = (THREADSTRUCT*)param;

    //here is the time-consuming process 
    //which interacts with your dialog
    AfxMessageBox ("Thread is started!");
    // TODO: Add your control notification handler code here
    cap.open(0);
    //VideoCapture cap("C:/Users/lsf-admin/Pictures/Camera Roll/video000.mp4");
    cv::vector<cv::Rect> faces;
    cv::Mat frame;
    cv::Mat graySacleFrame;
    cv::Mat original;
    if (!cap.isOpened())
    {

        AfxMessageBox(_T("Failed to load video file"));
        return 1;
        //return exit(1);
    }

    while (true)
    {
        cap >> frame;
        if (!frame.empty()){
        frame=ts->_this->detectFace(frame);
        //Display result
        CDC* vDC;
        vDC =ts->_this->GetDlgItem(IDC_VIDEO)->GetDC();
        CRect rect;
        ts->_this->GetDlgItem(IDC_VIDEO)->GetClientRect(&rect);
        IplImage* image2=cvCloneImage(&(IplImage)frame);
        ts->_this->DisplayIplImageToPictureBox(image2, vDC, rect); //img is IplImage* variable.
        ts->_this->ReleaseDC(vDC);
        cvReleaseImage(&image2);
        }
        if (cv::waitKey(30) >= 0) break;
    }

    //you can also call AfxEndThread() here
    return 1;
}

And I found the problem in the detectFace function. If I don't use it, the program works well. However, when I do it, and after 1 minutes, I click close button. it has error

Unhandled exception at at 0x760C4598 in DialogResize.exe: Microsoft C++ exception: cv::Exception at memory location 0x01A5EFB8.

The detectFace function is

cv::Mat CDialogResizeDlg::detectFace(cv::Mat image)
{
    // Load Face cascade (.xml file)
    //lbpcascades/lbpcascade_frontalface.xml
    if(image.empty())
    {
        image=NULL;
        return image;
    }
    // Detect faces
    std::vector<cv::Rect> faces;
     //detect face in gray image
    //convert image to gray scale and equalize
    cv::Mat graySacleFrame;
    cv::cvtColor(image, graySacleFrame, CV_BGR2GRAY);
    //equalizeHist(graySacleFrame, graySacleFrame);         
    face_cascade.detectMultiScale(graySacleFrame, faces, 1.1, 3, 0, cv::Size(90, 90));

    // Draw circles on the detected faces
    for( int i = 0; i < faces.size(); i++ )
    { 
        rectangle(image, faces[i], CV_RGB(0, 255, 0), 1);

    }

    return image;
}

I think the problem is free memory problem or detect face try to detect a empty image. I am not sure. Could you find my problem in above code. For full code. You can download at here

cv::Exception at memory location in MFC

I am using MFC to write GUI that allows to display video from webcam using opencv 2.4.10. However, I have a error that recorded in youtubehttp://youtu.be/j9Z-oKrDMoU .I using thread to show video. I used a thread to open and detect video.The thread is defined as

UINT CDialogResizeDlg::StartThread (LPVOID param)
{
    THREADSTRUCT*    ts = (THREADSTRUCT*)param;

    //here is the time-consuming process 
    //which interacts with your dialog
    AfxMessageBox ("Thread is started!");
    // TODO: Add your control notification handler code here
    cap.open(0);
    //VideoCapture cap("C:/Users/lsf-admin/Pictures/Camera Roll/video000.mp4");
    cv::vector<cv::Rect> faces;
    cv::Mat frame;
    cv::Mat graySacleFrame;
    cv::Mat original;
    if (!cap.isOpened())
    {

        AfxMessageBox(_T("Failed to load video file"));
        return 1;
        //return exit(1);
    }

    while (true)
    {
        cap >> frame;
        if (!frame.empty()){
        frame=ts->_this->detectFace(frame);
        //Display result
        CDC* vDC;
        vDC =ts->_this->GetDlgItem(IDC_VIDEO)->GetDC();
        CRect rect;
        ts->_this->GetDlgItem(IDC_VIDEO)->GetClientRect(&rect);
        IplImage* image2=cvCloneImage(&(IplImage)frame);
        ts->_this->DisplayIplImageToPictureBox(image2, vDC, rect); //img is IplImage* variable.
        ts->_this->ReleaseDC(vDC);
        cvReleaseImage(&image2);
        }
        if (cv::waitKey(30) >= 0) break;
    }

    //you can also call AfxEndThread() here
    return 1;
}

And I found the problem in the detectFace function. If I don't use it, the program works well. However, when I do it, and after 1 minutes, I click close button. it has error

Unhandled exception at at 0x760C4598 in DialogResize.exe: Microsoft C++ exception: cv::Exception at memory location 0x01A5EFB8.

The detectFace function is

cv::Mat CDialogResizeDlg::detectFace(cv::Mat image)
{
    // Load Face cascade (.xml file)
    //lbpcascades/lbpcascade_frontalface.xml
    if(image.empty())
    {
        image=NULL;
        return image;
    }
    // Detect faces
    std::vector<cv::Rect> faces;
     //detect face in gray image
    //convert image to gray scale and equalize
    cv::Mat graySacleFrame;
    cv::cvtColor(image, graySacleFrame, CV_BGR2GRAY);
    //equalizeHist(graySacleFrame, graySacleFrame);         
    face_cascade.detectMultiScale(graySacleFrame, faces, 1.1, 3, 0, cv::Size(90, 90));

    // Draw circles on the detected faces
    for( int i = 0; i < faces.size(); i++ )
    { 
        rectangle(image, faces[i], CV_RGB(0, 255, 0), 1);

    }

    return image;
}

I think the problem is free memory problem or detect face try to detect a empty image. I am not sure. Could you find my problem in above code. For full code. You can download at here

cv::Exception at memory location Bad input roi in MFCfunction cvInitImageHeader

I am using MFC to write GUI that allows to display video from webcam using opencv 2.4.10. However, I have a error that recorded in http://youtu.be/j9Z-oKrDMoU .I using thread to show video. I used a thread to open and detect video.The thread is defined asface. However, I have error is

UINT CDialogResizeDlg::StartThread (LPVOID param)
{
    THREADSTRUCT*    ts = (THREADSTRUCT*)param;

    //here is the time-consuming process 
    //which interacts with your dialog
    AfxMessageBox ("Thread is started!");
    // TODO: Add your control notification handler code here
    cap.open(0);
    //VideoCapture cap("C:/Users/lsf-admin/Pictures/Camera Roll/video000.mp4");
    cv::vector<cv::Rect> faces;
    cv::Mat frame;
    cv::Mat graySacleFrame;
    cv::Mat original;
    if (!cap.isOpened())
    {

        AfxMessageBox(_T("Failed to load video file"));
        return 1;
        //return exit(1);
    }

    while (true)
    {
        cap >> frame;
        if (!frame.empty()){
        frame=ts->_this->detectFace(frame);
        //Display result
        CDC* vDC;
        vDC =ts->_this->GetDlgItem(IDC_VIDEO)->GetDC();
        CRect rect;
        ts->_this->GetDlgItem(IDC_VIDEO)->GetClientRect(&rect);
        IplImage* image2=cvCloneImage(&(IplImage)frame);
        ts->_this->DisplayIplImageToPictureBox(image2, vDC, rect); //img is IplImage* variable.
        ts->_this->ReleaseDC(vDC);
        cvReleaseImage(&image2);
        }
        if (cv::waitKey(30) >= 0) break;
    }

    //you can also call AfxEndThread() here
    return 1;
}

And I found the problem "C:\\builds\\2_4_PackSlave-win32-vc11-shared\\opencv\\modules\\core\\src\\array.cpp:2918: error: (-25) Bad input roi in the detectFace function. If I don't use it, the program works well. However, when I do it, and after 1 minutes, I click close button. it has error

Unhandled exception at at 0x760C4598 in DialogResize.exe: Microsoft C++ exception: cv::Exception at memory location 0x01A5EFB8.
function cvInitImageHeader\n"

The detectFace function isproblem is in code

cv::Mat CDialogResizeDlg::detectFace(cv::Mat image)
{
 cv::VideoCapture cap;
   // Load Face cascade (.xml file)
    //lbpcascades/lbpcascade_frontalface.xml
    if(image.empty())
    {
        image=NULL;
        return image;
    }
    // Detect faces
    std::vector<cv::Rect> faces;
     //detect face in gray image
    //convert image to gray scale and equalize
    cv::Mat graySacleFrame;
    cv::cvtColor(image, graySacleFrame, CV_BGR2GRAY);
    //equalizeHist(graySacleFrame, graySacleFrame);         
    face_cascade.detectMultiScale(graySacleFrame, faces, 1.1, 3, 0, cv::Size(90, 90));

    // Draw circles on the detected faces
    for( int i = 0; i < faces.size(); i++ )
    { 
        rectangle(image, faces[i], CV_RGB(0, 255, 0), 1);

    }

    return image;
}
cap >> frame;

I think the problem is free memory problem or detect face try to detect a empty image. I am not sure. Could Can you find my problem in above code. help me resolve it? For full code. You can download at here.