I have character images like this:
Using following code I could get contours and convex hull, then I could draw convex for each character.
import cv2
img = cv2.imread('test.png', -1)
ret, threshed_img = cv2.threshold(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY),
127, 255, cv2.THRESH_BINARY)
image, contours, hier = cv2.findContours(threshed_img, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
for cnt in contours:
# get convex hull
hull = cv2.convexHull(cnt)
cv2.drawContours(img, [hull], -1, (0, 0, 255), 1)
print(hull)
cv2.imwrite("contours.jpg", img)
The result is as follows:
I could get hull coordinates like this (for one character):
[[[546 134]]
[[534 149]]
[[532 151]]
[[527 153]]
[[523 154]]
[[522 154]]
[[520 109]]
[[521 107]]
[[524 106]]
[[533 106]]
[[539 111]]
[[543 117]]
[[546 122]]]
Now I want to separate each character using convexHull
coordinates.
After separating, images would be like,
. . .
The main reason I want to use convexHull
coordinates is then I can segment characters which were overlapped in vertical image space. You can understand what I have meant by using following image:
I can't segment characters accurately since most of the images contain characters like above. So I want to segment characters using convexHull
coordinates.