8

我使用 OpenCV 在 C++ 中有这个函数:

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

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

  return vKeypoints;
}

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

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;
}

但是,一旦我两次调用此方法...

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;
}

...我收到以下错误:

在此处输入图像描述

谁能告诉我我的错误在哪里以及如何解决这个问题?我需要使用两个不同的图像两次调用此函数,但每次我这样做时都会收到此错误。

我正在使用 Visual Studio 2012。

4

3 回答 3

9

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

于 2014-01-23T07:00:07.053 回答
5

我也有相同的调试断言失败(dbgheap.c 行:1424 表达式:_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()
}

我的错误是我将系统 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) 的 Assertion failed 将不再发生。

@TheMotivation,您的回答启发了我。谢谢你。

于 2014-08-02T18:24:25.743 回答
0

这是库问题,在我的情况下,将项目属性“使用 mfc”从静态更改为“在共享 DLL 中使用 MFC”就可以了。

于 2018-04-13T05:10:10.233 回答