How to fill closed contours of edged text in Python [closed]
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:
After applying Candy edge i got this:
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)
# Fill out ALL Contours:
cv2.fillPoly(stencil, contours, color)
result = cv2.bitwise_and(img, stencil)
how am I supposed to get all the handwriting back, even the unclosed outlines?