百度AI功能还是很强大的,百度AI开放平台真的是测试接口的天堂,免费接口很多,当然有量的限制,但个人使用是完全够用的,什么人脸识别、MQTT服务器、语音识别等等,应有尽有。
看看OCR识别免费的量
快速安装:执行pip install baidu-aip即可
新建一个AipOcr:
from aip import AipOcr""" 你的 APPID AK SK """APP_ID = '你的 App ID'API_KEY = '你的 Api Key'SECRET_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('example.jpg')""" 调用通用文字识别, 图片参数为本地图片 """client.basicGeneral(image);""" 如果有可选参数 """options = {}options["language_type"] = "CHN_ENG"options["detect_direction"] = "true"options["detect_language"] = "true"options["probability"] = "true"""" 带参数调用通用文字识别, 图片参数为本地图片 """client.basicGeneral(image, options)url = "http///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)通用文字识别 请求参数详情
通用文字识别 返回数据参数详情
通用文字识别
from aip import AipOcr#更换为自己的注册信息APP_ID = '---'API_KEY = '---'SECRET_KEY = '---'client = AipOcr(APP_ID, API_KEY, SECRET_KEY)#创建连接fp=open("tu2.png","rb").read()#打开并读取文件内容res=client.basicGeneral(fp)#普通#print(res)#将所有的文字都合并到一起strx=""for tex in res["words_result"]:#遍历结果 strx+=tex["words"]#每一行print(strx)#输出内容最终代码
from aip import AipOcr # 定义常量APP_ID = '14544448'API_KEY = 'yRZGUXAlCd0c9vQj1kAjBEfY'SECRET_KEY = 'sc0DKGy7wZ9MeWFGZnbscbRyoDB2IQlj' # 初始化AipFace对象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('binary_best.jpg')# 调用通用文字识别, 图片为本地图片res=client.general(image)print(res) for item in res['words_result']: print(item['words'])例:
from aip import AipOcrimport reAPP_ID='17010327'API_KEY='X2MWCU1LG1PX5H6GAXgdlWD7'SECRET_KEY='vz6GZ6TkhSFvY3quqcuC3EG8oEW3kThB'client=AipOcr(APP_ID,API_KEY,SECRET_KEY)i=open(r'C:\Users\Administrator\Desktop\example.png','rb')image = i.read()result=client.basicGeneral(image)#将所有的文字都合并到一起for item in result['words_result']: print(item['words'])通用文字识别client.basicGeneral(image)
通用文字识别(高精度版)client.basicAccurate(image);
通用文字识别(含位置信息版)client.general(image);
通用文字识别(含位置高精度版)client.accurate(image);
通用文字识别(含生僻字版)client.enhancedGeneral(image);
网络图片文字识别client.webImage(image);
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。