【问题标题】:Debug Assertion Failed Expression: _pFirstBlock == pHead using OpenCV and C++ trying to call SurfFeatureDetector调试断言失败表达式:_pFirstBlock == pHead 使用 OpenCV 和 C++ 尝试调用 SurfFeatureDetector
【发布时间】:2014-01-21 15:02:28
【问题描述】:

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

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。

【问题讨论】:

    标签: c++ opencv dll surf visual-c++-runtime


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我也遇到了同样的调试断言失败(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)的断言失败不会再发生。

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-11
          • 1970-01-01
          • 2021-09-28
          • 1970-01-01
          • 2016-07-21
          相关资源
          最近更新 更多