基本信息
源码名称:多张图片识别文字(基于AipOcr)
源码大小:1.43KB
文件格式:.py
开发语言:Python
更新时间:2020-07-30
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
可以把多张图片上的文字直接生成WORD保存到桌面
import os
import random
from aip import AipOcr
APP_ID='21190173'
API_KEY='eKAS6DRfPYLjjccN1pyyv2Tn'
SECRET_KEY='qLYeSlv5WlHZX5v51Bqg6b5RYid2zkHr'
client=AipOcr(APP_ID,API_KEY,SECRET_KEY)
""" 如果有可选参数 """
options = {}
options["detect_direction"] = "false"
options["probability"] = "true"
aa=''.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 4))
ab='C:\\Users\\Admin\\Desktop\\多图识别结果' aa '.docx'
f = open(ab, "w", encoding='utf-8')
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilenames()
for file_name in file_path:
if(file_name.lower().endswith(('.bmp', '.dib', '.png', '.jpg', '.jpeg',
'.pbm','.pgm', '.ppm', '.tif', '.tiff'))):
image = open(file_name,'rb').read()
f.write(' 这张图片在:' file_name '\n\n\n')
else:
continue
""" 带参数调用通用文字识别(高精度版) """
""" 参数options可缺省"""
result = client.basicAccurate(image, options)
print(result)
try:
for i in range(int(result['words_result_num'])):
txt = result['words_result'][i]['words']
print(txt)
if len(txt) > 2:
f.write(txt '\n')
except:
pass
f.close()
可以把多张图片上的文字直接生成WORD保存到桌面
import os
import random
from aip import AipOcr
APP_ID='21190173'
API_KEY='eKAS6DRfPYLjjccN1pyyv2Tn'
SECRET_KEY='qLYeSlv5WlHZX5v51Bqg6b5RYid2zkHr'
client=AipOcr(APP_ID,API_KEY,SECRET_KEY)
""" 如果有可选参数 """
options = {}
options["detect_direction"] = "false"
options["probability"] = "true"
aa=''.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 4))
ab='C:\\Users\\Admin\\Desktop\\多图识别结果' aa '.docx'
f = open(ab, "w", encoding='utf-8')
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilenames()
for file_name in file_path:
if(file_name.lower().endswith(('.bmp', '.dib', '.png', '.jpg', '.jpeg',
'.pbm','.pgm', '.ppm', '.tif', '.tiff'))):
image = open(file_name,'rb').read()
f.write(' 这张图片在:' file_name '\n\n\n')
else:
continue
""" 带参数调用通用文字识别(高精度版) """
""" 参数options可缺省"""
result = client.basicAccurate(image, options)
print(result)
try:
for i in range(int(result['words_result_num'])):
txt = result['words_result'][i]['words']
print(txt)
if len(txt) > 2:
f.write(txt '\n')
except:
pass
f.close()