Step By Step
1.快速体验
体验地址
2.开通文字识别服务
票据凭证识别
3.获取您的真实AK信息
查看AK
4.添加python依赖
pip install alibabacloud_ocr_api20210707==1.1.1
5.Python SDK Code
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
from typing import List
from alibabacloud_ocr_api20210707.client import Client as ocr_api20210707Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ocr_api20210707 import models as ocr_api_20210707_models
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> ocr_api20210707Client:
"""
使用AK&SK初始化账号Client
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 您的AccessKey ID,
access_key_id='ak',
# 您的AccessKey Secret,
access_key_secret='sk'
)
# 访问的域名
config.endpoint = 'ocr-api.cn-hangzhou.aliyuncs.com'
return ocr_api20210707Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client('accessKeyId', 'accessKeySecret')
with open(r'C:\Users\cnc\Desktop\test.jpg', 'rb') as f: # 以二进制读取本地图片
data = f.read()
recognize_basic_request = ocr_api_20210707_models.RecognizeBasicRequest(
# url='https://duguang-mld.oss-cn-hangzhou.aliyuncs.com/data_pool/d125cde79dca3f0f876e9ce72fee7b99'
body=data
)
# 复制代码运行请自行打印 API 的返回值
res = client.recognize_basic(recognize_basic_request)
print(res)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client('accessKeyId', 'accessKeySecret')
recognize_basic_request = ocr_api_20210707_models.RecognizeBasicRequest(
url='https://cnc-us.oss-cn-shanghai.aliyuncs.com/pictures/test.jpg'
)
# 复制代码运行请自行打印 API 的返回值
await client.recognize_basic_async(recognize_basic_request)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
6.运行结果