Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Problem with findContours and drawContours

$
0
0
Hi, I'm new to OpenCV, I was trying to run this simple code to find the contours of an image: int main( int argc, char** argv ) { cv::Mat immat = cv::imread("board.jpg", 1); cv::Mat img; cv::cvtColor(immat, img, CV_BGR2GRAY); cv::Mat imcanny; cv::Canny (img,imcanny,75,150,3); std::vector> contours; cv::findContours(imcanny,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE); cv::drawContours(immat,contours,-1,CV_RGB(255,0,0),2); std::cout << "found " << contours.size() << " contours\n"; cv::imwrite("contours.png", immat); cv::waitKey(); return 0; } But there was something strange about the output of the contours, it looks like this when I checked it: ![image description](/upfiles/14037170487931928.gif) There are a lot of contours with an extremely huge size and all of their points are {x=??? y=???}. Is this normal output for findcontours function? Not only that, when I execute the program (release mode) to the end of the main function, I got two messages "myproject has triggered a breakpoint", after I pressed continue on both of them, I got "A heap has been corrupted" exception. While in debug mode, I got a Debug Assertion Failed: _CrtIsValidHeapPointer(pUserData). Everything else works fine if I comment the findContours and drawContours lines. How can I solve this problem? For more information, I was using VS2012 and OpenCV 2.49.

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>