问题:使用pytesseract库识别图片中文字时出现报错

代码:

import pytesseract
from PIL import Image,ImageEnhance
img=Image.open(r'F:\Test\venv\vfi_code.png') #修改图片的灰度,提高识别准确性
img=img.convert('RGB')
enhancer=ImageEnhance.Color(img)
enhancer=enhancer.enhance(0)
enhancer=ImageEnhance.Brightness(enhancer)
enhancer=enhancer.enhance(2)
enhancer=ImageEnhance.Contrast(enhancer)
enhancer=enhancer.enhance(8)
enhancer=ImageEnhance.Sharpness(enhancer)
img=enhancer.enhance(20) code=pytesseract.image_to_string(img,lang='chi_sim')
print(code)

原因:在安装pytesseract库后还需要安装Tesseract-OCR才能正常使用

解决办法:

1)先下载对应版本的Tesseract-OCR并安装,安装时记得把语言包都勾上。下载链接:Index of /tesseract

没有勾选语言包会有这个报错:

pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:\\Program Files\\Tesseract-OCR/tessdata/chi_sim.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'chi_sim\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')

2)将安装路径C:\Program Files\Tesseract-OCR 添加到系统环境变量Path里;再增加一个TESSDATA_PREFIX变量名,变量值还是我的安装路径C:\Program Files\Tesseract-OCR\tessdata这是将语言字库文件夹添加到变量中;

3)打开终端,输入:tesseract -v,可以看到版本信息

4)在pytesseract库下的pytesseract.py文件中找到tesseract_cmd = 'tesseract',修改成            tesseract_cmd =r'C:\Program Files\Tesseract-OCR\tesseract.exe'

5)再运行脚本就没有报错了

参考链接:https://www.jianshu.com/p/93ab58dea50f

解决:pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your PATH. See README file for more information.的更多相关文章

  1. pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path && FileNotFoundError: [WinError 2] 系统找不到指定的文件。

    C:\Users\k\Desktop\test>python test.py Traceback (most recent call last): File , in run_tesseract ...

  2. pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

    使用pytesseract识别验证码中遇到异常如下: pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installe ...

  3. 解决pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path问题

    解决方案: 找到python的安装路径下的pytesseract:   例如我的是  C:\develop\Python\Lib\site-packages\pytesseract .用文本编辑器打开 ...

  4. pytesseract.pytesseract.TesseractError: (1, 'Error opening data file /usr/local/share/tessdata/chi_sim.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata"

    pytesseract.pytesseract.TesseractError: (1, 'Error opening data file /usr/local/share/tessdata/chi_s ...

  5. 报错解决——pytesseract.pytesseract.TesseractError: (1,’Error opening data file /usr/local/share/tessdata/eng.traineddata’)

    解决方法:(原文地址http://stackoverflow.com/questions/14800730/tesseract-running-error) $ wget https://tesser ...

  6. tesseract-ocr和tesseract.exe is not installed or it's not in your path问题解决

    一.解决方案: 1.http://www.ddooo.com/softdown/94968.htm   打开下载的压缩包,找到"tesseract-ocr-setup-3.02.02.exe ...

  7. 解决: org.iq80.leveldb.DBException: IO error: C:\data\trie\000945.sst: Could not create random access file.

    以太坊MPT树的持久化层是采用了leveldb数据库,然而在抽取MPT树代码运行过程中,进行get和write操作时却发生了错误: Caused by: org.fusesource.leveldbj ...

  8. 解决tomcat开始出现in production environments was not found on the java.library.path:xxx

    如图所看到的,Eclipse中启动tomcat时出现not found on the java.library.path等信息.能够通过下载tomcat-native-1.1.32-win32-bin ...

  9. 如何解决"The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path"

    今天我在eclipse上搭建新项目时,莫名其妙的出现这个错误,如下: The superclass "javax.servlet.http.HttpServlet" was not ...

  10. 解决spark运行中failed to locate the winutils binary in the hadoop binary path的问题

    1.下载hadoop-common-2.2.0-bin并解压到某个目录 https://github.com/srccodes/hadoop-common-2.2.0-bin 2.设置hadoop.h ...

随机推荐

  1. (已解决)富文本编辑器:使用layui的layedit怎么回显存放在数据库里的富文本数据(包含有图片base64码)?

    1. 背景 我把富文本内容从后台导入到前端,回显在layui的layedit里面. 2. 步骤 直接在<textarea></textarea>中间进行赋值(我用的是模板赋值) ...

  2. 【BOOK】数据存储--MongoDB

    MongoDB存储 1.链接MongoDB        指定数据库        指定集合 import pymongo ## 连接数据库 client = pymongo.MongoClient( ...

  3. Object.assign() 方法浅析

    Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象.它将返回目标对象. const target = { a: 1, b: 2 ,c:3,e:6}; cons ...

  4. 算法学习—————PAM回文自动机

    时隔一年,第一次学习新的算法 原理和AC自动机差不多 基本思想: 两棵树分别代表奇偶 在一个回文串两边同时填上相同字符可以得到另一个回文串,以此构建两棵树 树上维护信息: 节点表示的回文串为当前位置的 ...

  5. jboss单机环境搭建

    1.操作系统:centos7 2.需要的包:apache,wildfly,postgres(要初始化),activemq 3.安装流程: 一.安装依赖包并部署服务:httpd,wildfly,mq,p ...

  6. Linux_CMD_FOR_FILE&FOLDER

    0,删除文件夹和子文件夹:rm -rf /xxx/xxx 0,拷贝整个文件夹:cp -r /xxx/xxx /ddd/ 0,改文件名:mv oldName newName 0,新建文件:touch f ...

  7. Java调试排错心得

    首先这里没有报错,但是打印了四行相同的数据,还都是最后一行的数据.然后调试了一下 这里是重点: 下面哪里account = {Account@1580}是一直用的一个对象,所有每一次调试那些什么rs. ...

  8. 7.mysql索引失效

          失效的七字口诀: 模型数空运最快 模:模糊查询以%开始索引失效: 型:数据类型转换 函数:函数的索引 空:索引列为空不走索引, 运:对索引列进行加减乘除会失效 最:不按聚合索引的最左匹配会 ...

  9. json 解析,JSON数组

    public class resuleobj { public int returncode { get; set; } public string message { get; set; } pub ...

  10. JupyterNotebook开发介绍

    简单介绍 核心目录在notebook下面,主页面在tempaltes目录下的notebook.html文件,没有用到传统的前端开发技术,还是jquery之类的前端,而且用了非常多的类库,开发环境的搭建 ...