pytesseract安装过程,教程很多、很多,这里就不赘述了如下链接:
https://blog.csdn.net/weixin_42341986/article/details/80882413
看重点、看重点、看重点
看到好多教程都讲到,在D:\Python37\Lib\site-packages\pytesseract路径下修改pytesseract.py文件
如:
将这个tesseract_cmd = 'tesseract' 改为:tesseract_cmd ='D:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
实际上正确修改方法
- 需要在tesseract_cmd = 'D:\Program Files (x86)\Tesseract-OCR\tesseract.exe’前面加个r,
tesseract_cmd =r‘D:\Program Files (x86)\Tesseract-OCR\tesseract.exe’
- 或不加r换为反斜杠
tesseract_cmd = 'D:/Program Files (x86)/Tesseract-OCR/tesseract.exe'(注:新手一定要注意/与\的区分)
- 再或不加r加双斜杆
tesseract_cmd ='D:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
这样执行完后应该不会再报系统找不到指定文件的错了……
如还报其他错就最后一个大招,重启电脑。我的就是修改完还报错,重启后大功告成。。。。。
#英文
import pytesseract
from PIL import Image
image = Image.open('D:/Python/selenium/project/diseasedetection/image.png')
vcode = pytesseract.image_to_string(image)
print (vcode)
#中文
import pytesseract
from PIL import Image
file_path="./pic/image.jpg"
image = Image.open(file_path)
vcode = pytesseract.image_to_string(image,lang="chi_sim")
print (vcode)