import easyocr报错
求大神指点报错
代码如下
import easyocr
import os
import re
import pandas as pd
class id_card_ocr():
def __init__(self): # 文件位置
self.images = r'D:/id_card' # 需要注意的是,图片文件的名称不能有汉字,否则会报错~
def ocr_reader(self): # 创建ocr对象,识别中英文
ocr = easyocr.Reader(['ch_sim','en'],gpu=True)
return ocr
def read_content(self): # 识别图片文字,并遍历
data = []
for image in os.listdir(self.images):
content = self.ocr_reader().readtext(f'{self.images}/{image}',detail=0)
content = ''.join(content) # 列表转换为纯文本
new_content = content.replace(" ", "") # 去除掉空格内容
print(f'正在识别:{image}')
name = re.findall(r'名(.*?)性', new_content)
gender = re.findall(r'别(.*?)民族|民', new_content)
nation = re.findall(r'族|民族(.*?)出', new_content)
address = re.findall(r'址(.*?)公', new_content)
number = re.findall(r'身份号码(\d+)', new_content)
new_name = ''.join(name)
new_gender = ''.join(gender)
new_nation = ''.join(nation)
new_address = ''.join(address)
new_number = ''.join(number)
if len(new_number) == 18: # 判断身份证的位数
pass
elif len(new_number) == 17:
new_number = new_number + "X"
print(f'完成识别:{image}')
data.append([new_name, new_gender, new_nation, new_address, new_number])
print(data)
return data
def read_to_excel(self):
df = pd.DataFrame(self.read_content(),columns = ['姓名','性别','民族','地址','身份证号码'])
print(f'识别结果如下:')
print(df)
df.to_excel(r'D:/id_card/识别结果.xlsx',index=False)
return df
if __name__ == '__main__':
info = id_card_ocr()
info.read_content()
info.read_to_excel()
报错如下
S C:\Users\Administrator> & C:/Users/Administrator/AppData/Local/Programs/Python/Python38/python.exe d:/批量识别身份证.py
Traceback (most recent call last):
File "d:/批量识别身份证.py", line 1, in <module>
import easyocr
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\easyocr\__init__.py", line 1, in <module>
from .easyocr import Reader
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\easyocr\easyocr.py", line 3, in <module>
from .detection import get_detector, get_textbox
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\easyocr\detection.py", line 11, in <module>
from .craft import CRAFT
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\easyocr\craft.py", line 11, in <module>
from .model.modules import vgg16_bn, init_weights
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\easyocr\model\modules.py", line 6, in <module>
from torchvision.models.vgg import model_urls
ImportError: cannot import name 'model_urls' from 'torchvision.models.vgg' (C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\torchvision\models\vgg.py)
PS C:\Users\Administrator>
相关推荐
easyocr的模型文件
在给定的“easyocr的模型文件”压缩包中,包含了这些模型,解压并放置到指定目录后,EasyOCR就能使用这些模型进行文本识别。在深入讲解EasyOCR之前,我们先了解一下OCR的基本概念。
【Python 基于EasyOCR库进行图片文字识别】
EasyOCR是一个python模块,用于从图像中提取文本。它是一个通用的OCR,既可以读取自然场景文本,也可以读取文档中的密集文本。OCR是Optical Character Recognition的缩写,光学字符识别的意思。输出的是列表格式,每一项分别代表文本框坐标[x,y]、文本和模型置信度的列表。输出的是列表格式,内容直接是识别到的文本,不分项。如果运行程序的时候,程序自动下载模型出错,或者中断。左边是支持的语言,右边是支持的语言对应的代码。输出的是列表格式,每一项是识别到的文本。
python的文字识别库easyocr所需中文识别的模型.zip
例如,通过导入EasyOCR库并加载模型,可以方便地读取图片并提取出文字内容:```pythonfrom easyocr import Reader# 加载中文识别模型reader = Reader([
easyocr模块.rar
标题中的"easyocr模块.rar"指的是一个压缩包文件,它包含了一个名为EasyOCR的Python库的相关模型资源。
easyOCR_pth.zip
这个“easyOCR_pth.zip”压缩包包含的是EasyOCR模型的权重文件,可能是一个预训练模型或者用户自定义训练的模型,用于识别图像中的文字。


IT课程大本营
