在VS 2010上使用findContours()的堆错误

时间:2016-03-05 20:03:26

标签: visual-studio opencv

调试代码时出现头错误。我的错误窗口说:

  

调试断言失败!
  文件:f:\ dd \ cvtools \ crt_bld \ self_x86 \ crc \ src \ dbgheap.c
  行:1322。

我试图修改它改变我的项目设置:将MFC链接为静态库或使用MFC作为共享DLL,但任何一个都解决了我的问题。

我认为当我使用函数findContours();

时,这是一个内存问题

我使用Visual Studio 2010和opencv 2.4.9。如果我在Vivado HLS上调试它,我没有任何问题。

编辑:我已经通过再次创建一个新的项目并从头开始配置库来解决了这个问题。有时很难知道你的目录和libreries设置有什么问题。非常感谢你的帮助Micka

 #include "opencv2/core/core.hpp"
 #include "opencv2/highgui/highgui.hpp""
 #include "opencv2/imgproc/imgproc.hpp"
 #include "iostream"

    using namespace cv;
    using namespace std;


    /** @function main */
    int main( int argc, char** argv )
    {
        Mat src = imread(argv[1], 1);

        // Mostrar la imagen original
        imshow("Original", src);

        Mat canny_output;
        vector<vector<Point> > contours;
        vector<Vec4i> hierarchy;

        int thresh = 100;

        // Detectar los bordes con un umbral min = 100 y max = 200
        Canny(src, canny_output, thresh, thresh * 2);

        // Mostrar los bordes detectados con Canny
        imshow("Bordes", canny_output);

        // Buscar los contornos de la imagen, se almacenan en contours
        findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

        // Mostrar la Imagen modificada por la funcion findContours
        imshow("Modificada", canny_output);

        // Dibujar los contornos encontrados
        Mat drawing = Mat::zeros(canny_output.size(), CV_8UC3);
        for (size_t i = 0; i< contours.size(); i++)
        {
         Scalar color = CV_RGB(0, 255, 0);
         drawContours(drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point());
        }

        // Mostrar la imagen final
        imshow("Contours", drawing);
        waitKey(3000);
      return 0;
      }

0 个答案:

没有答案