findcontours is not finding all the contours

asked 2013-05-29 17:40:22 -0500

codemonkey gravatar image

updated 2013-05-29 18:08:12 -0500

image description image description

I'm trying to get outlines of all of the color blobs in this image but between Canny and findContours, I'm not getting all of the contours. I attached the original image and one with the resulting contours drawn in white.

Here's my code:

// pad the image with a border of black pixels in case a hotspot is on the edge
cv::Mat matPadded = cv::Mat::zeros(cv::Size(matImage.size().width + 4, matImage.size().height + 4), CV_8UC3);
cv::Rect roi = cv::Rect(cv::Point(2, 2), matImage.size());
cv::Mat matROI = matPadded(roi);

cv::Mat matCanny;
cv::Canny(matPadded, matCanny, 50, 150);

// find contours
std::vector<std::vector<cv::Point>> aContours;
cv::findContours(matCanny, aContours, aHierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));

Any tips on how I can get better results? I tried converting the image to grayscale first but it was even worse.

edit retag flag offensive close merge delete