Python:IOError: image file is truncated 的解决办法
代码如下:
#coding:utf-8
from PIL import Image
import pytesseract
def test():
im = Image.open(r"pic.gif")
vcode = pytesseract.image_to_string(im)
print vcode
执行以上代码进行简单验证码识别的时候会抛出一个异常:
Traceback (most recent call last):
File "D:\test\vcode.py", line 15, in <module>
main()
File "D:\test\vcode.py", line 9, in main
test()
File "D:\test\test.py", line 8, in test
vcode = pytesseract.image_to_string(im)
File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 143, in image_to_string
File "D:\Program Files (x86)\Python\Python27\lib\site-packages\PIL\Image.py", line 1749, in split
self.load()
File "D:\Program Files (x86)\Python\Python27\lib\site-packages\PIL\ImageFile.py", line 232, in load
"(%d bytes not processed)" % len(b))
IOError: image file is truncated (5 bytes not processed)
解决办法是,再添加如下2句代码:
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
最终,完整的代码如下:
#coding:utf-8
from PIL import Image
import pytesseract
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
def test():
im = Image.open(r"pic.gif")
vcode = pytesseract.image_to_string(im)
print vcode
相关文章:
关于利用python进行验证码识别的一些想法:http://www.cnblogs.com/xiaowuyi/archive/2012/09/10/2675286.html
python利用pytesser模块实现图片文字识别:http://www.jinglingshu.org/?p=9281
验证码图片字符识别两种python实现方法:http://vipscu.blog.163.com/blog/static/18180837220134234528457/
python模拟登陆登陆一:验证码与cookies的同步处理思路:http://www.dabu.info/python-login-crawler-captcha-cookies.html
原文地址:http://www.cnblogs.com/hongfei/p/4436767.html
Python:IOError: image file is truncated 的解决办法的更多相关文章
- [转]tftp在put上传的时候显示File not found的解决办法
[转]tftp在put上传的时候显示File not found的解决办法 http://blog.163.com/pengcz%40126/blog/static/35908607201182433 ...
- 执行shell脚本时提示bad interpreter:No such file or directory的解决办法
执行shell脚本时提示bad interpreter:No such file or directory的解决办法 故障现象:在终端直接cd /var正常,在shell脚本中执行则报错.原因是脚本是 ...
- VS2012与VS2015同时安装用VS2012创建MFC程序时弹出编译错误”fatal error C1083: 无法打开包括文件:“mprapidef.h”: No such file or directory”的解决办法
在WIndows 7操作系统上同时安装VS2012与VS2015并用VS2012创建MFC程序时弹出编译错误”fatal error C1083: 无法打开包括文件:“mprapidef.h”: No ...
- UI进阶 XML解析适配 'libxml/tree.h'file not found 错误解决办法
Xcode 'libxml/tree.h'file not found 错误解决办法
- 对于python中“FileNotFoundError: [Errno 2] No such file or directory”的解决办法
在我们使用vscode运行Python代码时遇到的情况 一.出现原因:这里是由于Vscode中,python里的路径是相对与工作目录来进行定位的.所以在多级目录情况下,若不设置绝对路径,往往找不到相应 ...
- PYTHON -MYSQLDB安装遇到的问题和解决办法
目前下载的mysqldb在window下没有exe安装包了,只有源码. 使用python setup.py install 命令安装, 报错如下: 异常信息如下: F:\devtools\MySQL- ...
- python程序一直在后台运行的解决办法
刚写了个python程序,要一直在后台运行,即使断开ssh进程也在,下面是解决办法: 假如Python程序为test.py 编写shell脚本start.sh #!/bin/bash python t ...
- 【linux】CentOS安装mysql*.rpm提示conflicts with file from package的解决办法
使用以下命令安装: rpm -ivh MySQL-server-5.6.19-1.linux_glibc2.5.x86_64.rpm 错误提示如下: Preparing... ...
- [转]pro*c/c++编译错误 ” error: sqlca.h: No such file or directory “ 的解决办法
$ gcc -o test test.c 出现错误:error: sqlca.h: No such file or directory [解决方法]知道 sqlca.h 在 $ORACLE_HOME/ ...
随机推荐
- Median of Two Sorted Arrays
题目:https://leetcode.com/problems/median-of-two-sorted-arrays/ 算法分析 这道题的目的,是为了从两个有序列中找到合并序列之后的中位数,即两个 ...
- php 生日提醒程序
<?php $startdate=time(); //当前时间 $birth="2013-05-13"; // 出生日期 $arr=explode(" ...
- MySQL报错“1366 - Incorrect integer value: '' XXXXXXX' at row 1 ”
出现这个错误是因为我在表中插入了一条含有中文字符的语句: 修改方法:(两种) 1:命令行 set names gbk:(此为设置通信编码) 2:my.ini中查找sql-mode 将 sql-mod ...
- nop 添加字段
一.Libraries 1.core 层------------实体字段 2.data-Map----------映射到数据库 二.Admin 1.Models --------admin界面模型 ...
- nodejs: 理解Buffer
学习nodejs中buffer这一章,有一段写到buffer的拼接,其中一段源码非常优美,特拿来与大家共享. var chunks = []; var size = 0; res.on('data', ...
- 修改VNC分辨率大小
实验系统是centos6.5,在被连接的机器上需要安装vncserver. 1.第一种方法:使用geometry参数进行调整使用man命令获得关于geometry参数的描述[root@secdb ~] ...
- 总结一下一般游戏中3D模型各种勾边方法遇到的工程性问题
以前做过简单的rim light勾边,几何勾边,这次又做了后处理的勾边,工程化的时候,都遇到很多问题,简单总结一下. 首先是火炬之光勾边效果,类似轮廓光的实现,简单的卡通渲染也是通过类似的算法加采样色 ...
- SQL中的取整函数FLOOR、ROUND、CEIL、TRUNC、SIGN
1 trunc(value,precision)按精度(precision)截取某个数字,不进行舍入操作.2 round(value,precision)根据给定的精度(precision)输入数值. ...
- 记一次SQLServer数据库误删数据找回
昨天 同事在本机清理数据库表时,连接到了生产机,误删了二十几张表,幸好是晚上加班的时候删除的,生产机上当时是一天一备份,还原备份是最后的策略,最关键的还是要找回数据. ...
- 【WinHec启示录】透过Windows 10技术布局,谈微软王者归来
每个时代都有王者,王者的成功,往往是因为恰逢其时地发布了一个成功的产品(具有里程碑意义,划时代的产品).Windows 95的成功标示着微软是PC时代的王者:WinXP的成功标示着微软是互联网时代的王 ...