Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to fill closed contours of edged text in Python

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?

How to fill closed contours of edged text in Python

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

cv2 > import numpy as np

...

...

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

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

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

np.zeros(img.shape).astype(img.dtype) > color = [255, 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

for cnt in contours:

Contours:

 cv2.fillPoly(stencil, cnt, contours, color)

result = cv2.bitwise_and(img, stencil)

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?

How to fill closed contours of edged text in Python

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?

How to fill closed contours of edged text in Python

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?

How to fill closed contours of edged text in Python

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?

How to fill closed contours of edged text in Python

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?