在验证码代码中出现UnicodeDecodeError问题

codeleej 2017-12-06 11:38:59
代码,问题如下,有没有能解决的啊,谢谢
# coding:utf-8

import pytesseract
from PIL import Image
import os


image=Image.open(r'c:\code.jpg')
pytesseract.tesseract_cmd=r'c:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
code=pytesseract.image_to_string(image)
print(code)


Traceback (most recent call last):
File "C:\Users\李杰\Desktop\python_study\12\ocr.py", line 10, in <module>
code=pytesseract.image_to_string(image)
File "C:\Users\李杰\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 124, in image_to_string
...全文
278 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
落地生根1314 2019-03-20
  • 打赏
  • 举报
回复
我也遇到同样的问题: Traceback (most recent call last): File "G:/Project-Code/idcard_detect/idcard_identification_v1/IDcard/idcard_test_function.py", line 108, in <module> info, img = IDCard("test1.png") File "G:/Project-Code/idcard_detect/idcard_identification_v1/IDcard/idcard_test_function.py", line 102, in IDCard Information=text_get(Name, Sex, Nationality, Birth_year, Birth_month, Birth_day, Address, ID_number) File "G:\Project-Code\idcard_detect\idcard_identification_v1\IDcard\idcard_ocr.py", line 103, in text_get out_name = tesseractChinese(Name) File "G:\Project-Code\idcard_detect\idcard_identification_v1\IDcard\Tesserast_ocr.py", line 24, in tesseractChinese result = pytesseract.image_to_string(Image.fromarray(img),lang='utf-8',config='-psm 3') File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\pytesseract\pytesseract.py", line 309, in image_to_string }[output_type]() File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\pytesseract\pytesseract.py", line 308, in <lambda> Output.STRING: lambda: run_and_get_output(*args), File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\pytesseract\pytesseract.py", line 218, in run_and_get_output run_tesseract(**kwargs) File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\pytesseract\pytesseract.py", line 194, in run_tesseract raise TesseractError(status_code, get_errors(error_string)) File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\pytesseract\pytesseract.py", line 93, in get_errors line for line in error_string.decode('utf-8').splitlines() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 12: invalid start byte 大家有解决方法吗? 环境win10, Anaconda3 , py3.6
碧水幽幽泉 2017-12-06
  • 打赏
  • 举报
回复
可能是路径中带中文引起的。 把李杰去掉看看。
oyljerry 2017-12-06
  • 打赏
  • 举报
回复
应该是pytesseract这个库对于这个验证码不支持

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧