Debug Assertion Failed Expression:_pFirstBlock == pHead使用OpenCV和C++试图调用SurfFeatureDetector

Mic*_*key 8 c++ dll opencv surf visual-c++-runtime

我在使用OpenCV的C++中有这个功能:

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

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

  return vKeypoints;
}
Run Code Online (Sandbox Code Playgroud)

当我在main方法中调用此函数时,一切正常.

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;
}
Run Code Online (Sandbox Code Playgroud)

但是只要我两次打电话给这个方法......

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;
}
Run Code Online (Sandbox Code Playgroud)

...我收到以下错误:

在此输入图像描述

谁能告诉我我的错误在哪里以及如何解决这个问题?我需要使用两个不同的图像调用此函数两次,但每次执行此操作时都会出现此错误.

我正在使用Visual Studio 2012.

Mic*_*key 8

我发现了自己的错误.我不小心复制了VC12文件夹的openCV-dll,因为我忘记了Visual Studio 2012是VC11.现在它有效.也许这会帮助其他有同样问题的人并复制错误文件夹的dll.


小智 5

我也有相同的Debug Assertion Failed(dbgheap.c Line:1424 Expression:_pFirstBlock == pHead).我使用Visual Studio 2012 Professional(vc11)使用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()
}
Run Code Online (Sandbox Code Playgroud)

我的错误是我将系统PATH变量设置为OpenCV x64路径(c:\ opencv\build\x64\vc11\bin)但我将我的代码与VC2012项目中的x86库链接.

在Windows中重新定义PATH变量以更正OpenCV x86路径(c:\ opencv\build\x86\vc11\bin)并重新启动我的VC2012后,dbgheap.c(1424)的断言失败将不会再次发生.

@TheMotivation,你的回答激发了我的灵感.谢谢.