title: OpenCV: The result of findContours cannot be filled
body: <p>I use the OpenCV and <code>findContours</code> method to find the contour of the polygon that can be filled.   Basically the result image should look the same as an input. The image I provide is already black and white, so it doesn't need to be converted to grayscale. </p>
  
  <p>The issue I'm having is that the result of <code>findContours</code> cannot always be filled. The <code>drawContours</code> can draw nice contours, but the thickness = FILLED works only sometimes (meaning it doesn't work in the presented example, but it can work on similar input). Initially blurring the image, increases the chance of success, but it's still not a very reliable solution.</p>
  
  <p><a href="https://i.stack.imgur.com/VcLer.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VcLer.png" alt="enter image description here"></a></p>
  
  <pre><code>// blur( src_gray, src_gray, Size(2,2) ); - blurring an image with different kernel sizes might help sometimes
  
  Canny( src_gray, canny_output, thresh, thresh*2, 3 );
  findContours( canny_output, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0, 0) );
  
  Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
  for(int i = 0; i &lt;contours.size(); i++ ) {
      drawContours( drawing, contours, i, Scalar(255, 255, 255), FILLED, 8);
  }
  </code></pre>
  
  <p>I tried to verify what's wrong with result contours after converting it to a polygon with BOOST library and it tells me that the <code>Geometry has invalid self-intersections</code> or it has <code>spikes</code>. In this case it's unable to correct it.</p>
  
  <p>Is there any better solution that can give me filled shape, assuming that drawing just contours works really well?</p>