前言
这是我以前参考百度官方文档写的,平时做课题报告遇到不好复制文献会用这个来进行文字识别(虽然没有别人写成软件的方便)。
正文
不多废话直接上代码
from aip import AipOcr
""" 你的 APPID AK SK """
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
def get_file_content(filePath):
""" 读取图片 """
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('') # 填入本地图片位置
""" 调用通用文字识别, 图片参数为本地图片 """
client.basicGeneral(image)
""" 如果有可选参数 """
options = {}
options["detect_direction"] = "true"
options["detect_language"] = "true"
options["probability"] = "true"
""" 带参数调用通用文字识别, 图片参数为本地图片 """
result = client.basicGeneral(image, options)
result = result["words_result"]
for x in result:
words = x["words"]
print(words)
# url = "https//www.x.com/sample.jpg"
""" 调用通用文字识别, 图片参数为远程url图片 """
# client.basicGeneralUrl(url)
# """ 如果有可选参数 """
# options = {}
# options["language_type"] = "CHN_ENG"
# options["detect_direction"] = "true"
# options["detect_language"] = "true"
# options["probability"] = "true"
#
# """ 带参数调用通用文字识别, 图片参数为远程url图片 """
# client.basicGeneralUrl(url, options)
识别准确率还是挺高的
总结
什么时候我能自己搞文字识别,机器学习,人工智能,大数据处理······?