python-3.x - 无法使用pytesseract.image_to_string识别单词

标签 python-3.x opencv tesseract

我有旋转文本的图像。我正在获取此文本的位置并将其裁剪,然后旋转此文本。到此为止,我可以看到文字完美显示。但是现在,如果我将旋转后的文本发送到“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, 0, 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)
Cropped Image
Rotated Image
识别的文本:“Ol Ey”
我的代码有什么问题吗?任何帮助都感激不尽。

最佳答案

我确实尝试过旋转的图像,我在这里所做的唯一一件事就是反转照片,我设法获得一致的结果。
enter image description here

rotated = cv2.bitwise_not(rotated)
enter image description here

关于python-3.x - 无法使用pytesseract.image_to_string识别单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64038556/

相关文章:

python - 3D 中的径向基函数(面向奇异矩阵)

android - 使用 Cygwin 编译 Android-OpenCV 库

java - 从 java 中使用 Tesseract

ios - 仅在我的 iOS 应用程序中将 tesseract 字符限制为 a-z 和数字

python - 在Python中发送电子邮件(MIMEmultipart)

python - 在引发错误中引发

c++ - 在 C++ 中支持 cuda 的错误 opencv

ocr - Tesseract 是否提供整个图像的置信度分数?

python - 如何检查列表是否已包含 Python 中的元素?

python - boxPoints 返回负 y 值