title: Filling holes inside a binary object
body: <p>I have a problem with filling white holes inside a black coin so that I can have only 0-255 binary images with filled black coins. I have used a Median filter to accomplish it but in that case connection bridge between coins grows and it goes impossible to recognize them after several times of erosion... So I need a simple <code>floodFill</code> like method in opencv</p>
  <p>Here is my image with holes:</p>
  <p><img src="https://i.stack.imgur.com/d1tAc.png" alt="enter image description here" /></p>
  <p><strong>EDIT:</strong> <code>floodfill</code> like function must fill holes in big components without prompting X, Y coordinates as a seed...</p>
  <p>EDIT: I tried to use the <code>cvDrawContours</code> function but it doesn't fill contours inside bigger ones.</p>
  <p>Here is my code:</p>
  <pre><code>        CvMemStorage mem = cvCreateMemStorage(0);
          CvSeq contours = new CvSeq();
          CvSeq ptr = new CvSeq();
          int sizeofCvContour = Loader.sizeof(CvContour.class);
          
          cvThreshold(gray, gray, 150, 255, CV_THRESH_BINARY_INV);
          
          int numOfContours = cvFindContours(gray, mem, contours, sizeofCvContour, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
          System.out.println(&quot;The num of contours: &quot;+numOfContours); //prints 87, ok
          
          Random rand = new Random();
          for (ptr = contours; ptr != null; ptr = ptr.h_next()) {
              Color randomColor = new Color(rand.nextFloat(), rand.nextFloat(), rand.nextFloat());
              CvScalar color = CV_RGB( randomColor.getRed(), randomColor.getGreen(), randomColor.getBlue());
              cvDrawContours(gray, ptr, color, color, -1, CV_FILLED, 8);
          }
          CanvasFrame canvas6  = new CanvasFrame(&quot;drawContours&quot;);
          canvas6.showImage(gray);
  </code></pre>
  <p>Result: (you can see black holes inside each coin)</p>
  <p><img src="https://i.stack.imgur.com/baiy5.png" alt="enter image description here" /></p>