import json
import cv2
import requests
import uuid
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.tmt.v20180321 import tmt_client
from tencentcloud.tmt.v20180321 import models as tmt_models
import numpy as np
import base64
import matplotlib.pyplot as plt
%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
SecretId="xxxxxxxxxxxxxxxxxxxxxxxxx"
SecretKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"""
图片翻译
https://console.cloud.tencent.com/api
/explorer?Product=tmt&Version=2018-03-21&Action=ImageTranslate&SignVersion=
"""
try:
cred = credential.Credential(SecretId, SecretKey)
httpProfile = HttpProfile()
httpProfile.endpoint = "tmt.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tmt_client.TmtClient(cred, "ap-beijing", clientProfile)
img_path="./images/en1.jpg"
with open(img_path,"rb") as file:
img=base64.b64encode(file.read())
req = tmt_models.ImageTranslateRequest()
params = {
"SessionUuid": str(uuid.uuid4()),
"Scene": "doc",
"Data": str(img,encoding='utf-8'),
"Source": "auto",
"Target": "zh",
"ProjectId": 0
}
req.from_json_string(json.dumps(params))
resp = client.ImageTranslate(req).to_json_string()
resp=json.loads(resp)
print(resp)
except TencentCloudSDKException as err:
print(err)
{'SessionUuid': '6f0143ef-91d9-46f3-bd7a-7878510defa6', 'Source': 'en', 'Target': 'zh', 'ImageRecord': {'Value': [{'SourceText': 'These socially responsible ETFs', 'TargetText': '', 'X': 50, 'Y': 58, 'W': 492, 'H': 36}, {'SourceText': 'cater to ESG investors.', 'TargetText': '', 'X': 54, 'Y': 98, 'W': 350, 'H': 28}, {'SourceText': 'Investors around the world are embracing strategies', 'TargetText': '', 'X': 54, 'Y': 148, 'W': 520, 'H': 22}, {'SourceText': 'that align with their personal values as well as their', 'TargetText': '', 'X': 50, 'Y': 180, 'W': 512, 'H': 22}, {'SourceText': 'pocketbooks. The clearest evidence of this is the rise', 'TargetText': '', 'X': 50, 'Y': 212, 'W': 532, 'H': 28}, {'SourceText': 'of exchange-traded funds with an expressed desire to', 'TargetText': '', 'X': 54, 'Y': 244, 'W': 532, 'H': 28}, {'SourceText': 'filter investments based on environmental, social and', 'TargetText': '', 'X': 50, 'Y': 278, 'W': 536, 'H': 26}, {'SourceText': 'corporate governance characteristics - or so-called', 'TargetText': '', 'X': 54, 'Y': 314, 'W': 512, 'H': 22}, {'SourceText': '"ESG" qualities. Last year, ESG ETF assets surpassed', 'TargetText': '', 'X': 54, 'Y': 346, 'W': 524, 'H': 24}, {'SourceText': 'CREDIT', 'TargetText': '', 'X': 944, 'Y': 278, 'W': 68, 'H': 18}, {'SourceText': '问', 'TargetText': '', 'X': 928, 'Y': 278, 'W': 20, 'H': 18}, {'SourceText': '$190 billion and accounted for almost 13% of global ETF asset growth, and that pace has not', 'TargetText': '', 'X': 54, 'Y': 378, 'W': 926, 'H': 28}, {'SourceText': 'slowed down with a projected footprint of $53 trillion by 2025,according to Bloomberg. So what', 'TargetText': '', 'X': 54, 'Y': 412, 'W': 954, 'H': 26}, {'SourceText': 'are the leading funds capturing investors interest right now? Here are seven socially responsible', 'TargetText': '', 'X': 54, 'Y': 444, 'W': 957, 'H': 26}, {'SourceText': 'ESG ETFs to consider. All of them boast a few billion dollars under management.', 'TargetText': '', 'X': 54, 'Y': 476, 'W': 800, 'H': 28}]}, 'RequestId': '5ae5a320-c0ea-47b0-b639-94670666a46e'}