分类
大小:25.1 MB
语言:简体中文系统:WinXP, Win2003, Vista, Win7, Win8, Win10
类别:文字处理时间:2019-07-18
python图片文字识别扫描工具是一款文字识别软件,软件基于Python和百度识别接口设计而来,可快速识别图片中的文字,写入TXT文件,支持快捷键F1截屏,虽说是基于命令行的操作,但是操作也算简单,需要的朋友可以下载!
1.放在软件目录下 可识别图片中的文字 并写入txt文件
2.可识别特定截屏软件的 图片中的文件
其中
APP_ID = 'xxxxxx'
API_KEY = 'xxxxxx'
SECRET_KEY = 'xxxxxx' 需要去百度AI研究一下就ok了 ,里面有许多免费的接口,值得看一下
import osfrom aip import AipOcr
import keyboard
from PIL import ImageGrab
from time import sleep
def get_reuslt(img_name):
a=input('是否添加可信度?(建议字多不加) (y/n):')
if a == 'y':
APP_ID = 'xxxxxx'
API_KEY = 'xxxxxx'
SECRET_KEY = 'xxxxxx'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """
with open(img_name, 'rb') as fp:
image = fp.read()
""" 如果有可选参数 """
options = {}
options["detect_direction"] = "true"
options["probability"] = "true"
""" 带参数调用通用文字识别(高精度版) """
client = client.basicAccurate(image, options)
print(type(client))
for i in client['words_result']:
reuslt = i['words']
Credibility = i['probability']['average']
wyc=reuslt+" 平均可信度为:"+str((Credibility) * 100) + '%'
print(wyc)
with open(img_name+'.txt','a',encoding='utf-8') as f :
f.write(wyc+'\n')
print("文本已经保存本地")
else:
APP_ID = '16689194'
API_KEY = 'jXW5sEC420DZidAwMFMGQGsI'
SECRET_KEY = '5LRvxbPip8ZIdkM31rNs7Zo6d5o2Wv8q'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """
with open(img_name, 'rb') as fp:
image=fp.read()
""" 如果有可选参数 """
options = {}
options["detect_direction"] = "true"
options["probability"] = "false"
""" 带参数调用通用文字识别(高精度版) """
client=client.basicAccurate(image, options)
for i in client['words_result']:
reuslt=i['words']
print(reuslt+'\t')
with open(img_name+'.txt','a',encoding='utf-8') as f :
f.write(reuslt+'\n')
print("文本已经保存本地" )
def jietu():
while 1:
keyboard.wait('f1','')
keyboard.wait('ctrl+c')
sleep(0.2)
image = ImageGrab.grabclipboard()
# 从剪贴版获取图片
image.save('截图.jpg')
for filename in os.listdir(r"./"):
if (filename.endswith('.jpg')) or (filename.endswith('.png')) or (filename.endswith('.bmp')):
get_reuslt(filename)
print('请继续截图....')
def main():
for filename in os.listdir(r"./"):
if (filename.endswith('.jpg')) or (filename.endswith('.png')) or (filename.endswith('.bmp')) :
get_reuslt(filename)
input("结束请按Enter键")
if __name__ == '__main__':
print('********'*2+'我秒选托儿所!!!!'+'********'*2+'\n')
print('截屏识别填1,图片识别填2:')
pd=input('')
if pd=='2':
print('***************请将图片放置本目录下***************')
a=input("我已将图片放好? (y/n):")
if a=='y':
main()
else:
pass
else:
print('只支持快捷键F1截屏,需要按 Ctrl+c 将图片存到剪贴板...')
print('请开始截图.......')
jietu()
展开