我的预感是轮廓区域会告诉您路径的复杂程度。
我会采用更简单的指标,例如轮廓的高度 boundingRect()
:
#!/usr/bin/env python
import cv2
import numpy as np
filename = 'boyfriend.png'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,dst = cv2.threshold(gray,127,255,0)
# erode and negate to amplify edges
dst = cv2.erode(dst,None,iterations=2)
dst = (255-dst)
cv2.imshow('thresh',dst)
contours,hierarchy = cv2.findContours(dst,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
if len(contours) > 1:
# print bounding box height per contour for debugging purposes
print([cv2.boundingRect(cnt)[3] for cnt in contours])
# filter contours where the bounding box height matches the image height
conts = [cnt for cnt in contours if cv2.boundingRect(cnt)[3] == img.shape[0]]
# preview
img = cv2.drawContours(img,conts,-1,(0,0),3)
cv2.imshow('img',img)
cv2.waitKey(0)
注意 3 个轮廓边界框高度突出:
[127,16,35,15,36,18,17,220,220]
您可能希望将条件更改为阈值而不是确切值。
例如
# if the contour bounding box height is > 3/4 of the image height
cv2.boundingRect(cnt)[3] > img.shape[0] * 0.75
上面的完整代码产生:
请注意,我使用了 morphological filter 来放大边缘。
它适用于具有这些迭代的图像,因为过滤器将框轮廓扩展得足够多,但不会与文本/字符合并。
这可能需要针对其他图像进行调整。
更新 快速搜索后,我发现了一些可能有趣的资源:
Kumiko
Kumiko,Comics Cutter 是一套工具,用于计算有关漫画书页、面板等的有用信息。它的主要优势是找出漫画页面(图像文件)中面板的位置。 Kumiko 还可以编译一本漫画书中所有页面的面板信息,并将其呈现为一个数据(JSON 格式的对象)。
Segmentation and indexation of complex objects in
comic book images(与您的要求不同,但可能对后续步骤有用)
本文链接:https://www.f2er.com/622235.html