目录
3)获取accessKeyId、accessKeySecret
4.json文件主要信息(举例信息以字典形式给出)
1.调用费用
新用户拥有200次调用次数
调用费用:1千次套餐包120元(优惠价83.29元)(首次购买享0.01元购买)
1万次套餐包800元(优惠价550元)
官方链接:计费介绍 (aliyun.com)
2.调用流程
1)注册阿里云账号
阿里云链接:阿里云-为了无法计算的价值 (aliyun.com)
2)开通服务
选(华东2上海)
链接:文字识别 (aliyun.com)
3)获取accessKeyId、accessKeySecret
右上角点击控制台--鼠标移至用户名处--下拉栏中--AccessKey管理--
4)运行代码(当前输入图片格式为url)
代码修改初始信息:accessKeyId、accessKeySecret、img_path、save_path
# -*- coding: utf-8 -*-
import sys
from typing import List
from alibabacloud_ocr20191230.client import Client as ocr20191230Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ocr20191230 import models as ocr_20191230_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
accessKeyId = 'LTAI5tGtkhv87ecsByeCPTtE'
accessKeySecret = ''
url = 'https://my-new-backet.oss-cn-shanghai.aliyuncs.com/0M208145r02110zw_1.png?Expires=1666167623&OSSAccessKeyId=TMP.3KjomAgZat996u5VtB8XKfLmrCgrd3QC2zRR4ApN9mfff9K76yiJDsbNb15MumeQwWWrnVmJ1MfuZeDxc5XoagCbESzPVR&Signature=teDwkb7E352KIRwiIgNWsrPDNE0%3D'
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> ocr20191230Client:
"""
使用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=access_key_id,
# 您的 AccessKey Secret,
access_key_secret=access_key_secret
)
# 访问的域名
config.endpoint = f'ocr.cn-shanghai.aliyuncs.com'
return ocr20191230Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
print("start")
client = Sample.create_client(accessKeyId, accessKeySecret)
recognize_table_request = ocr_20191230_models.RecognizeTableRequest(
image_url=url,
output_format='xlsx',
use_finance_model=False,
skip_detection=False,
has_line=False,
assure_direction=False
)
runtime = util_models.RuntimeOptions()
try:
# 复制代码运行请自行打印 API 的返回值
response = client.recognize_table_with_options(recognize_table_request, runtime)
print(response)
response = response.to_map() # to --> dict()
res_id = response["body"]["RequestId"]
print(res_id)
res = client.get_async_job_result(response)
print(res)
except Exception as error:
# 如有需要,请打印 error
print(error)
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client(accessKeyId, accessKeySecret)
recognize_table_request = ocr_20191230_models.RecognizeTableRequest(
image_url=url,
output_format='xlsx',
use_finance_model=False
)
runtime = util_models.RuntimeOptions()
try:
# 复制代码运行请自行打印 API 的返回值
response = client.recognize_table_with_options_async(recognize_table_request, runtime)
print(response)
print(response.to_dict())
except Exception as error:
# 如有需要,请打印 error
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
3.本地文件生成URL
1)登录OSS管理控制台(oss存储服务需要付费)
2).创建存储空间
Bucket列表--创建Bucket--地域选择“华东2(上海)”
点击进入Bucket列表中创建好的Bucket
获取url: