1

I am using OpenCV2.4.3 findContours function. But some output contours are not closed.

   cv::cvtColor(m_Image, src, COLOR_BGR2GRAY);
   blur(src,srcFiltered, cv::Size(3,3));
   cv::Canny(srcFiltered, edge, 20, 10, 3);
   vector<vector<cv::Point>> vecContours;
   vector<Vec4i> vecHierarchy;
   findContours(edge, vecContours, vecHierarchy, CV_RETR_CCOMP ,CV_CHAIN_APPROX_NONE);
   typedef cv::Vec<uchar,3> U8C3Elem;
   Mat contours = Mat::ones(src.rows, src.cols, CV_8UC1)*255;
   for(size_t i=0; i<vecContours.size(); ++i)
   {
      vector<cv::Point>& vec = vecContours.at(i);

      // draw contours
      U8C3Elem clr = U8C3Elem(rand()%255, rand()%255, rand()%255);
      for(int j=0; j<vec.size(); ++j)
      {
         m_Image.at<U8C3Elem>(vec.at(j)) = clr;
      }
   }

I am referred to some image processing books, the contour is defined as closed curve. In the image below, lines with different color stand for different contours find by findContours function. So, who has idea? Thanks!

This is the image with contours http://images.cnitblog.com/blog/374163/201301/18232515-fee482f8a641429f8c8b08081545a2c5.png

4

0 回答 0