drawContours as is, not filled, not just outline
Hi,
With cv2.drawContours is there a way to draw the exact contour as is? Not just the border, or not completely filled.
I'm using it for extracting alphabets from a text, and for characters like A, P, 4 etc, it fills them inside as well.
Eg: Input Binary Image:
Extracted problematic characters after drawContours:
Adding Code:
for contour in countours:
mask = np.zeros(img.shape[:2], dtype="uint8")
mask.fill(255)
cv2.drawContours(mask, [contour], 0, 0, cv2.FILLED)
x,y,w,h = cv2.boundingRect(contour)
charImg = mask[y:y+h, x:x+w]
cv2.imwrite('char', charImg)
how do you call it ?
added code
cv2.drawContours(mask, [contour], 0, 0, 2)
That will draw the boundary with thickness and not the actual matching contour region.
It's important to note that a contour is just the boundary. So the inner part of those letters would be a different contour.
If you use connectedComponents you get the filled area, which may be more what you want. connectedComponentsWithStats will even return bounding boxes. It is important to note that it will return ALL the WHITE portions of the image and a separate component.
@Akash Budhia Pay attention to Contours Hierarchy value. It will help you in your case. More detail : hierarchy