2013-07-30 33 views
0

由於cv :: findContours函數,我有一個堆損壞錯誤。我需要幫助找出解決這個問題的方法。findContours堆中的Curroption錯誤

int GetEndPoints(cv::Mat image) 
{ 
    cv::Mat imgBW = cv::Mat::zeros(image.rows, image.cols, CV_8UC1); 
    cv::cvtColor(image, imgBW, CV_BGR2GRAY); 

    std::cout << std::endl << imgBW.channels(); 
    cv::threshold(imgBW, imgBW, 150, 255, cv::THRESH_BINARY); 
    cv::namedWindow("image", 0); 
    cv::imshow("image", imgBW); 
    std::vector<std::vector<cv::Point>> contours; 
    cv::Mat image1 = image.clone(); 


    // Find the Contours 
    std::cout << std::endl << imgBW.channels(); 
    cv::findContours(imgBW, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE); 
    cv::drawContours(image1, contours, -1, cv::Scalar(255, 0, 0), 2, 8); 
    cv::namedWindow("contours", 0); 
    cv::imshow("contours", image1); 
    cv::waitKey(); 

    return 0; 
} 
+0

我用g ++ 4.7.2和opencv 2.3.1試過了你的程序。我沒有收到關於堆損壞的消息。我也通過valgrind運行它,並沒有出現任何錯誤。 –

+0

我正在使用Visual Studio 2010的opencv 2.4.5。正如我深入,我覺得問題是在刪除輪廓矢量。 – amoghesturi

+0

我看到相同的問題,並得出了相同的結論:錯誤是由我通過超出範圍傳遞的向量造成的。使用Visual Studio 2015和OpenCV 2.4。也許它是特定於Windows版本?你有沒有找到解決方案? –

回答

0

你應該檢查找到的輪廓數。當輪廓中沒有等高線變化時,我認爲你會發生錯誤。