简体   繁体   English

每当我使用 pytesseract.image_to_string 它都会导致错误

[英]Whenever I use pytesseract.image_to_string it results in an error

import pytesseract
import cv2
img = cv2.imread('ocrtest.jpg')   
img = cv2.resize(img, (600,400))
print(pytesseract.image_to_string(img))
cv2.imshow('Result', img)
cv2.waitKey(0)

Whenever I add line 5 - the print(pytesseract.image_to_string(img)) line - , it results in this giant error saying file not found error, and at the very bottom it says tesseract not found.每当我添加第 5 行 - print(pytesseract.image_to_string(img)) 行 - 时,它会导致这个巨大的错误,说 file not found 错误,并且在最底部它说 tesseract not found。 I am using Anaconda Jupyter notebook, and pytesseract is downloaded in the Anaconda file, not the Jupyter notebook file on my desktop.我正在使用 Anaconda Jupyter notebook,pytesseract 下载在 Anaconda 文件中,而不是我桌面上的 Jupyter notebook 文件中。 Could that be the problem?这可能是问题吗? If that line is not added, the code runs correctly and opens up the image file.如果未添加该行,则代码将正确运行并打开图像文件。 The jpg image is downloaded within the desktop folder. jpg 图像下载到桌面文件夹中。

The ndarray from opencv is not support for pytesseract text extraction. opencv 的 ndarray 不支持 pytesseract 文本提取。 Make use of pillow instead of opencv-python .使用枕头代替opencv-python

import pytesseract
from PIL import Image
img = Image.open("ocrtest.jpg")
resized_img = img.resize((600,400))
print(pytesseract.image_to_string(resized_img))
img.show()

Hope this will help you.希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM