【发布时间】:2018-06-18 01:50:11
【问题描述】:
到目前为止,我尝试过的是使用 OpenCV 来获取边缘 代码:
def autocrop(image, threshold=0):
"""Crops any edges below or equal to threshold
Crops blank image to 1x1.
Returns cropped image.
"""
if len(image.shape) == 3:
flatImage = np.max(image, 2)
else:
flatImage = image
assert len(flatImage.shape) == 2
rows = np.where(np.max(flatImage, 0) > threshold)[0]
if rows.size:
cols = np.where(np.max(flatImage, 1) > threshold)[0]
image = image[cols[0]: cols[-1] + 1, rows[0]: rows[-1] + 1]
else:
image = image[:1, :1]
return image
no_border = autocrop(new_image)
cv2.imwrite('no_border.png',no_border)
结果是这张图片,接下来如何移除那些框
更新:
我发现该解决方案适用于白色背景,但是当我更改背景颜色时,边框不会被删除
已编辑
我已经尝试了这张图片的解决方案
但是结果是这样的
我怎样才能完全去除边界框。
【问题讨论】:
-
我已经编写了一个简洁的代码来使用轮廓中的层次概念来识别字符。无需编写复杂的代码来裁剪和切割。请看下面的答案!