小编Bob*_*ops的帖子

在pytesseract中使用image_to_osd方法时出现错误

这是我的代码:

import pytesseract
import cv2
from PIL import Image

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"


def main():
    original = cv2.imread('D_Testing.png', 0)
    # binary thresh it at value 100. It is now a black and white image
    ret, original = cv2.threshold(original, 100, 255, cv2.THRESH_BINARY)
    text = pytesseract.image_to_string(original, config='--psm 10')
    print(text)
    print(pytesseract.image_to_osd(Image.open('D_Testing.png')))


if __name__ == "__main__":
    main()
Run Code Online (Sandbox Code Playgroud)

对于第一个输出,我得到了我需要的字母D

D
Run Code Online (Sandbox Code Playgroud)

这是有意的,但是当它尝试执行第二个打印语句时,它会吐出它。

Traceback (most recent call last):
  File "C:/Users/Me/Documents/Python/OpenCV/OpenCV_WokringTest/PytesseractAttempt.py", line 18, in <module>
    main()
  File "C:/Users/Me/Documents/Python/OpenCV/OpenCV_WokringTest/PytesseractAttempt.py", line 14, in main
    print(pytesseract.image_to_osd(Image.open('D_Testing.png')))
  File "C:\Users\Me\Documents\Python\OpenCV\OpenCV_WokringTest\venv\lib\site-packages\pytesseract\pytesseract.py", line 402, …
Run Code Online (Sandbox Code Playgroud)

ocr tesseract python-3.x python-tesseract pytesser

7
推荐指数
3
解决办法
673
查看次数

标签 统计

ocr ×1

pytesser ×1

python-3.x ×1

python-tesseract ×1

tesseract ×1