测试了下识别图片,效果比自己写的强多了,价格也不贵,以后就用这个了。
参考:
https://ai.baidu.com/forum/topic/show/867951?castk=48016gq7963d9fc64d294
https://cloud.baidu.com/doc/OCR/s/7kibizyfm
代码如下:
from aip import AipOcr
""" 你的 APPID AK SK """
APP_ID = '24471254'
API_KEY = 'Hj3stMZ1jAGdfL6wIO14dSlWct'
SECRET_KEY = 'jn1G6CjlPtSsEpmOGREOQ4eN2R58aVXT0zt'
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('ceshi3.png')
""" 调用通用文字识别, 图片参数为本地图片 """
r = client.basicGeneral(image)
print(r)
# """ 如果有可选参数 """
# options = {}
# options["language_type"] = "CHN_ENG"
# options["detect_direction"] = "true"
# options["detect_language"] = "true"
# options["probability"] = "true"
#
# """ 带参数调用通用文字识别, 图片参数为本地图片 """
# client.basicGeneral(image, options)
#
# 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)