腾讯API调用(python调用ocr为例)
1. 搜索
https://console.cloud.tencent.com/
2. 点接口文档
3. 点API3.0 Explorer
4.输入id和key
id和Key由下面5、6步可得
5. 点查看密钥
6.新建密钥
附代码:
'''
客户端:https://console.cloud.tencent.com/api/explorer?Product=ocr&Version=2018-11-19&Action=GeneralBasicOCR&SignVersion=
'''
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.ocr.v20181119 import ocr_client, models
import base64
try:
cred = credential.Credential("id", "key")
httpProfile = HttpProfile()
httpProfile.endpoint = "ocr.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = ocr_client.OcrClient(cred, "ap-guangzhou", clientProfile)
image_path = '../mayun.jpg'
with open(image_path, 'rb') as f: # 以二进制读取本地图片
data = f.read()
encodestr = str(base64.b64encode(data), 'utf-8') # base64编码图片
req = models.GeneralBasicOCRRequest()
params = '{"LanguageType":"auto"}'
req.from_json_string(params)
req.ImageBase64 = encodestr
# req.ImageUrl="https://mc.qcloudimg.com/static/img/6d4f1676deba26377d4303a462ca5074/image.png"
resp = client.GeneralBasicOCR(req)
print(resp.to_json_string())
for text in resp.TextDetections: # 输出文字
print(text.DetectedText)
except TencentCloudSDKException as err:
print(err)