Reputation: 749
In the opencv documentation it says:
If mode equals to RETR_CCOMP or RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1).
After sending a converted image to the function, I got 180k contours, resulting the black mess below, if I plot them. So what does RETR_FLOODFILL
do and how do I use it correctly?
img = cv2.imread("lena.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_, contours, _ = cv2.findContours(image=np.array(img, dtype=np.int32), mode=cv2.RETR_FLOODFILL, method=cv2.CHAIN_APPROX_SIMPLE)
len(contours)
Out[7]: 183295
Upvotes: 6
Views: 6484
Reputation: 1855
I think it does whatever function cv2.floodFill
does. Finds all the pixels that are:
1-connected to each other
2-have intensity values close to each other
and consider them as a connected component. For example In your sample image, you have 183295 groups of pixels that are stick together and have a close intensity.
Upvotes: 3