Debug Assertion Failed Expression: _pFirstBlock == pHead using OpenCV and C++ trying to call SurfFeatureDetector

梦想的初衷 提交于 2019-12-09 05:46:16

问题


I have this function in C++ using OpenCV:

vector<KeyPoint> test(Mat img)
{
  int minHessian = 400;
  SurfFeatureDetector detector( minHessian );

  vector<KeyPoint> vKeypoints;
  detector.detect( img, vKeypoints );

  return vKeypoints;
}

When I call this function in my main-method everything works fine.

int main( int, char** argv )
{
    // path to a image-file
    char* input = "image.jpg";

    // read image into Mat img
    Mat img = imread( input, CV_LOAD_IMAGE_GRAYSCALE );

    // call function test
    test(img);

    waitKey(0);
    return 0;
}

But as soon as I'm calling this method twice...

int main( int, char** argv )
{
    // path to a image-file
    char* input = "image.jpg";

    // read image into Mat img
    Mat img = imread( input, CV_LOAD_IMAGE_GRAYSCALE );

    // call function test
    test(img);
    test(img); // <-- !!! second call

    waitKey(0);
    return 0;
}

...I get the following error:

Can anyone tell me where my mistake is and how I could fix this? I need to call this function twice with two different images, but every time I do this I get this error.

I'm using Visual Studio 2012.


回答1:


I've found my mistake. I accidentally copied the openCV-dlls of the VC12 folder, because I forgot that Visual Studio 2012 is VC11. Now it works. Maybe this will help someone else who has the same problem and copied the dlls of the wrong folder.




回答2:


I also had the same Debug Assertion Failed (dbgheap.c Line:1424 Expression: _pFirstBlock == pHead). I am using Visual Studio 2012 Professional (vc11) to compile with OpenCV 2.4.9.

int main(){
    SurfFeatureDetector detector(50);
    std::vector<KeyPoint> keypoints[502];
    //In my case, some ranges in for-loop may success without Assertion failed.
    for(int j=0;j<502;j++){
        sprintf(filename, "../../%06d.bmp", j);
        img[j] = imread(filename);
        detector.detect(img[j], keypoints[j]);
        waitKey(10);
    }
    printf("leaving main()\n");
    //Debug Assertion Failed after leaving main()
}

My mistake is that I set the system PATH variable to OpenCV x64 path (c:\opencv\build\x64\vc11\bin) but I linked my code with x86 libs in VC2012 project.

After redefine the PATH variable in Windows to correct OpenCV x86 path (c:\opencv\build\x86\vc11\bin) and restart my VC2012, the Assertion failed of dbgheap.c(1424) will not happened again.

@TheMotivation, Your answer inspired me. Thank you.




回答3:


It is library problem,in my case changed the project property "Use of mfc" from static to "Use MFC in a Shared DLL" do the trick.



来源:https://stackoverflow.com/questions/21261709/debug-assertion-failed-expression-pfirstblock-phead-using-opencv-and-c-tr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!