如何解决无法使用pytesseract.image_to_string识别单词
我的图像带有旋转文字。我正在获取此文本的位置并将其裁剪,然后旋转此文本。到此为止,我可以看到文字完美显示。但是现在,如果我将旋转后的文本发送到“ pytesseract.image_to_string”,则无法识别该文本。这是代码。
croped = orig[y:y+h,x:x+w].copy()
cv2.imshow('cropped ',croped)
text_img = cv2.cvtColor(croped,cv2.COLOR_BGR2GRAY)
text_img_nt = cv2.bitwise_not(text_img)
cv2.imshow('text img not ',text_img_nt)
thresh = cv2.threshold(text_img_nt,255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
coords = np.column_stack(np.where(thresh > 0))
angle = cv2.minAreaRect(coords)[-1]
if angle < -45:
angle = -(90 + angle)
else:
angle = -angle
(h,w) = text_img_nt.shape[:2]
center = (w // 2,h // 2)
M = cv2.getRotationMatrix2D(center,angle,1.0)
rotated = cv2.warpAffine(text_img_nt,M,(w,h),flags=cv2.INTER_CUBIC,borderMode=cv2.BORDER_REPLICATE)
cv2.imshow('rotated',rotated)
cv2.waitKey(100000)
config='-l eng --oem 1 --psm 3'
textRecognized = pytesseract.image_to_string(rotated,config = config,lang ='eng')
print(textRecognized)
可识别文字:“ Ol Ey”
我的代码有问题吗?任何帮助将不胜感激。
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。