admin管理员组文章数量:1654028
图片灰度化报错:PIL.UnidentifiedImageError: cannot identify image file
- 一、现象
- (一)第一个报错
- (二)第二个报错
- 二、解决过程
- 第一个报错解决
- 第二个报错解决过程
一、现象
(一)第一个报错
import pytesseract#tesserocr 变成了pytesseract
from PIL import Image
images = Image.open('验证.png')
images = images.convert('L')
print(pytesseract.image_to_string(images))
#image_to_text(images)#已经没有了
'''验证失败'''
#灰度化
images.show()
#print(pytesseract.image_to_string(image))
#二值化
threshold = 40
table =[]
for i in range(256):
if i < threshold:
table.append(0)
else:
table.append(1)
image = images.point(table,'1')
result = pytesseract.image_to_string(image)
print('ok')
print(result)
验证时出现路径错误:
原报错就是此处,进入这个界面需要最后一个报错路径处打开
进入此处
报错地点在这里:报错时位置并不是这样(此处已经更改完成了)
(二)第二个报错
报错
PIL.UnidentifiedImageError: cannot identify image file 'J:\\PyCharm项目\\项目\\项目二_文书内容提取\\提取模板模块\\parrot_new.png'
二、解决过程
第一个报错解决
更新路径即找到路径
将路径更新为现在路径即可
第二个报错解决过程
更新pillow
更换另一个图片后可以说明可能是该图片或者是其路径有问题
更换路径后仍然一样:
重新对图片进行检查发现,图片错误
只能对图片进行更新!!!!!!!
重新下载后
from PIL import Image
image_path ='J:\PyCharm项目\项目\项目二_文书内容提取\输出模块\parrot_new.png'
image = Image.open(image_path)
im_gray = image.convert('L')
im_gray.show()
成功
版权声明:本文标题:重装系统后:tesseract 和 图片灰度化报错-PIL.UnidentifiedImageError: cannot identify image file 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729649930a1208918.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论