调用百度OCR`
#读配置文件
conf = configparser.ConfigParser()
configpath = os.path.dirname(os.path.abspath(__file__))+"/config.ini"
logger.debug("configpath:"+configpath)
conf.read(configpath)
APP_ID = conf.get("baiduocr", "APP_ID")
API_KEY = conf.get("baiduocr", "API_KEY")
SECRET_KEY = conf.get("baiduocr", "SECRET_KEY")
# 初始化百度接口
aipocr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
# 读取图片
def get_file_content(filepath):
with open(filepath, 'rb') as fp:
return fp.read()
try:
resp = urllib.request.urlopen(imgurl)
resp1 = urllib.request.urlopen(imgurl)
src = np.asarray(bytearray(resp.read()), dtype="uint8")
src = cv.imdecode(src, cv.IMREAD_COLOR)
sp = src.shape
s = sp[1]
image=resp1.read()
except Exception as e:
logger.error(e,exc_info=True)
# 定义参数变量
options = {
'detect_direction': 'true',
'language_type': 'CHN_ENG',
'recognize_granularity': 'small'
}
# 调用通用文字识别接口
a = aipocr.accurate(image, options)