python包:pip install baidu-aip
详细教程:https://www.jianshu.com/p/e10dc43c38d0
我的代码:
import json
import os
import shutil
import cv2
from aip import AipOcr
from tqdm import tqdm
# """ 你的 APPID AK SK 图2的内容"""
APP_ID = '27145052'
API_KEY = '26T8PoG7inAFTF3MF99E0Pbg '
SECRET_KEY = 'CCbIfR0f9wLMgPXs3c0G6MTYwawpwZXi '
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
rootpath = r"C:\Users\dong.xie\Desktop\xsz111\学生证\u=693650192"
print(rootpath)
res = {}
files = os.listdir(rootpath)
for file in tqdm(files):
try:
fname = os.path.join(rootpath, file)
image = get_file_content(fname)
""" 调用通用文字识别, 图片参数为本地图片 """
results = client.general(image)
res[fname] = results
except:
print("error", fname)
最好的方式还是ocr+docker:
https://github.com/PaddlePaddle/PaddleOCR