LuoKeRen123
洛克人123
采纳率0%
2018-11-19 13:40

python 使用pytesseract出现的问题

40

import pytesseract
import os
from PIL import Image

pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tessdata/tesseract.exe'
img=Image.open(r'C:/Users/Administrator/Desktop/123.jpg')

vcode = pytesseract.image_to_string(img,lang='chi_sim')
print vcode

代码很简单,但是执行了之后会报错:
File "D:/python_anzhuang/wenjian/pachong3.py", line 9, in
vcode = pytesseract.image_to_string(img,lang='chi_sim')
File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 294, in image_to_string
File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 192, in run_and_get_output
File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 107, in save_image
File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 99, in prepare
TypeError: Unsupported image object

尝试了很多方法都不行,发现一个现象,在pytesseract.py源文件里面随意增加代码对程序本身不影响,所以很好奇执行的pytesseract.py路径在哪里?跪求大神解答,解决可提供报酬。
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • weixin_42778984 无良小师叔 2年前

    image = img.convert('RGB')
    把这句加在open下一句

    点赞 评论 复制链接分享
  • weixin_39416561 lyhsdy 3年前

    找到pytesseract库里的pytesseract.py文件

    找到:tesseract_cmd = 'tesseract'

    改成:tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'

    tesseract_cmd = r'Tesseract安装路径'

    作者:LGX_TvT
    来源:CSDN
    原文:https://blog.csdn.net/l1336037686/article/details/78409661
    版权声明:本文为博主原创文章,转载请附上博文链接!

    点赞 评论 复制链接分享

相关推荐