Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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:

image description

Extracted problematic characters after drawContours:

image description image description image description

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:

image description

Extracted problematic characters after drawContours:

image description image description image description

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)
    charImg = mask[y:y+h, x:x+w]
    cv2.imwrite('char', charImg)

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:

image description

Extracted problematic characters after drawContours:

image description image description image description

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)
    cv2.rectangle(debugPlate, (x, y), (x+w, y+h), (0,255,0), 2)
    charImg = mask[y:y+h, x:x+w]
    cv2.imwrite('char', charImg)

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:

image description

Extracted problematic characters after drawContours:

image description image description image description

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)
    cv2.rectangle(debugPlate, (x, y), (x+w, y+h), (0,255,0), 2)
x,y,w,h = cv2.boundingRect(contour)
    charImg = mask[y:y+h, x:x+w]
    cv2.imwrite('char', charImg)

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:

image description

Extracted problematic characters after drawContours:

image description image description image description

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)