【发布时间】:2018-10-27 18:44:58
【问题描述】:
我有这样的角色图像:
使用以下代码,我可以获得轮廓和凸包,然后我可以为每个字符绘制凸包。
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)
结果如下:
我可以得到这样的船体坐标(对于一个角色):
[[[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]]]
现在我想使用convexHull 坐标分隔每个字符。
分离后的图像会是这样的,
。 . .
我想使用convexHull 坐标的主要原因是我可以分割在垂直图像空间中重叠的字符。您可以使用以下图片来理解我的意思:
我无法准确地分割字符,因为大多数图像都包含上述字符。所以我想用convexHull坐标分割字符。
【问题讨论】:
标签: python opencv crop image-segmentation convex-hull