重装系统后:tesseract 和 图片灰度化报错-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()

成功
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章