How to fill closed contours of edged text in Python

asked 2020-01-26 22:13:38 -0500

Kamoba gravatar image

updated 2020-01-27 20:17:17 -0500

Hi everyone!

I'm working on a project to convert handwritings into a plot from which I'll try to convert it into gcode. Here with Open CV I'm trying to find the best way to convert handwritings to Clear Plot.

Image original: I try to work in poor condition, hence the rotten quality of the paper:

image description

After applying Candy edge i got this: image description

 import cv2

 import numpy as np



 contours, hier = cv2.findContours(edgedImage.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

 mask = cv2.imread("./scripts/mask.png")                # image white color

 stencil = np.zeros(img.shape).astype(img.dtype)

 color = [255, 255, 255]

 # Fill out ALL Contours

 for cnt in contours:

       cv2.fillPoly(stencil, cnt, color)

 result = cv2.bitwise_and(img, stencil)

 cv2.imwrite("result.jpg", result)

image description

# Fill out ALL Contours:

cv2.fillPoly(stencil, contours, color)

result = cv2.bitwise_and(img, stencil)

image description

how am I supposed to get all the handwriting back, even the unclosed outlines?

edit retag flag offensive close merge delete