gpt4 book ai didi

python - 从图像 : Python 中检测非文本数据

转载 作者:太空宇宙 更新时间:2023-11-03 14:38:53 24 4
gpt4 key购买 nike

enter image description here有什么方法可以从包含文本的图像中提取非文本数据吗?我有一张图片,比方说一封包含文字、签名和 Logo 的信件。我只想提取标志和 Logo ,或者更确切地说删除所有文本内容。有什么办法吗?提前致谢。

最佳答案

python解决方案:

import cv2
image = cv2.imread("test.png", 1)
img = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU,img)
cv2.bitwise_not(img,img)
rect_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (30, 5))
img = cv2.morphologyEx(img, cv2.MORPH_CLOSE, rect_kernel)
im2, contours, hier = cv2.findContours(img, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

if len(contours) != 0:
for c in contours:
x,y,w,h = cv2.boundingRect(c)
if(h>20):
cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),1)

cv2.imshow("Result", image)
cv2.waitKey(0)

结果:

enter image description here

关于python - 从图像 : Python 中检测非文本数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55036072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com