我在尝试去掉下面这张图片的边框:
到目前为止,我尝试使用OpenCV获取边缘,代码如下:
这句话的英译中文是:“结果就是这张图片,下一步怎样去掉那些框框。” 更新:
我发现这个解决方案适用于白色背景,但是当我改变背景颜色时,边框没有被移除。 已编辑:
我已经尝试了这张图片上的解决方案。 但是结果就像这样。 我如何实现完全删除边界框。
![enter image description here](https://istack.dev59.com/BmNkM.webp)
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)
这句话的英译中文是:“结果就是这张图片,下一步怎样去掉那些框框。” 更新:
我发现这个解决方案适用于白色背景,但是当我改变背景颜色时,边框没有被移除。 已编辑:
我已经尝试了这张图片上的解决方案。 但是结果就像这样。 我如何实现完全删除边界框。