python利用百度利用百度AI实现文字识别功能实现文字识别功能
本文为大家分享了python实现文字识别功能大全,供大家参考,具体内容如下
1.通用文字识别通用文字识别
# -*- coding: UTF-8 -*-
from aip import AipOcr
# 定义常量
APP_ID = '11352343'
API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE'
SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os'
# 初始化AipFace对象
aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
# 读取图片
filePath = "test3.png"
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)
print(result)
words_result=result['words_result'] for i in range(len(words_result)):
print(words_result[i]['words'])
2.网络图片文字识别网络图片文字识别
识别一些网络上背景复杂,特殊字体的文字。
# -*- coding: UTF-8 -*-
from aip import AipOcr
# 定义常量
APP_ID = '11352343'
API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE'
SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os'
# 初始化AipFace对象
aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
# 读取图片
filePath = "2-5.jpg"
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
options={}
options["detect_direction"] = "true" #检测朝向
options["detect_language"] = "true" #检测语言
评论10