我有一个从图像中突出显示用户名的代码,我想从该图像中提取文本,即用户名。下面是代码
import matplotlib.pyplot as plt
import cv2
import easyocr
from pylab import rcParams
from IPython.display import Image
rcParams['figure.figsize'] = 8, 16
reader = easyocr.Reader(['en'])
output = reader.readtext('MP-SAMPLE1.jpg')
cord = output[-106][0]
x_min, y_min = [int(min(idx)) for idx in zip(*cord)]
x_max, y_max = [int(max(idx)) for idx in zip(*cord)]
image = cv2.imread('MP-SAMPLE1.jpg')
cv2.rectangle(image,(x_min,y_min),(x_max,y_max),(0,0,255),2)
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
我已经根据我的图像设置了坐标,你可以根据你的图像进行调整,我需要提取矩形框下高亮显示的文本。 我是这个领域的新手,请忽略我会犯的任何错误
这是我对这个问题的部分解决办法
既然你是初学者,让我给你一个建议,总是从预处理开始
预处理将帮助您删除不需要的工件
例如,您可以执行
thresholding
:Thresholding-result或
median
筛选:Median-filter result我使用了
thresholding
,然后您可以使用pytesseract
库。该库包含大量的configuration options对于非英语语言,您也可以遵循此tutorial
因此,您希望文本位于
FATHERS HUSBANDS
旁边。因此,我们可以这样做将图像转换为文本
从文本中,找到
FATHERS HUSBANDS
的等价物结果:
姓氏正确,但名字部分正确,应该是
BRAJMONAN
我写下了这个答案,希望你能找到你的答案。祝你好运
代码:
相关问题 更多 >
编程相关推荐