Note that there are some explanatory texts on larger screens.

plurals
  1. POFilling holes inside a binary object
    primarykey
    data
    text
    <p>I have a problem with filling white holes inside a black coins so that I can have only 0-255 binary image with filled black coins.. I have used 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 floodFill 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> floodfill like function must fill holes in big components without prompting X,Y coordinates as a seed...</p> <p>EDIT: I tried to use cvDrawContours function but I 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("The num of contours: "+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("drawContours"); 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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload