# -*- coding: utf-8 -*-
"""
Created on Tue May 1 13:16:01 2018
@author: Administrator
"""
######################################################################
from aip import AipOcr
import json
# 定义常量
APP_ID = ' '
API_KEY = ' '
SECRET_KEY = ' '
######
i = 1
a = str(i)+'.txt'
f = open(a,'a')
# 初始化AipFace对象
aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
# 读取图片
for i in range(2):
a = str(i+1)+'.png'
filePath = a
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
# 定义参数变量
options = {
'detect_direction': 'true',
'language_type': 'CHN_ENG',
}
# 调用通用文字识别接口
result = aipOcr.basicGeneral(get_file_content(filePath), options)
for item in result['words_result']:
if('中考' in item['words'] and '20' in item['words']): ###题型
f.close()
i = i+1
a = str(i)+'.txt'
f = open(a,'a')
f.write(item['words'])
else:
f.write(item['words'])
f.write("\n")#换行
print(item['words'])
百度 orc识别图片转文字
最新推荐文章于 2022-07-19 17:45:17 发布