有道智云AI中图片翻译的调用

输入:

import sys import uuid import requests import base64 import hashlibfrom imp import reloadreload(sys)YOUDAO_URL = 'https://openapi.youdao.com/ocrtransapi' APP_KEY = '52e26e4e138d3c5d' APP_SECRET = 'DS72VRjbC4zHQFsVwSkh6qMgG50KzAXz'def truncate(q): if q is None: return None size = len(q) return q if size <= 20 else q[0:10] + str(size) + q[size - 10:size]def encrypt(signStr): hash_algorithm = hashlib.md5() hash_algorithm.update(signStr.encode('utf-8')) return hash_algorithm.hexdigest()def do_request(data): headers = {'Content-Type': 'application/x-www-form-urlencoded'} return requests.post(YOUDAO_URL, data=https://www.it610.com/article/data, headers=headers)def connect(): f = open(r'3.png', 'rb')# 二进制方式打开图文件(添加自己的图片具体路径) q = base64.b64encode(f.read()).decode('utf-8')# 读取文件内容,转换为base64编码 f.close()data = https://www.it610.com/article/{} data['from'] = 'zh-CHS' data['to'] = 'en' data['type'] = '1' data['q'] = q salt = str(uuid.uuid1()) signStr = APP_KEY + q + salt + APP_SECRET sign = encrypt(signStr) data['appKey'] = APP_KEY data['salt'] = salt data['sign'] = signresponse = do_request(data) print(response.content)if __name__ == '__main__': connect()

【有道智云AI中图片翻译的调用】输出:
有道智云AI中图片翻译的调用
文章图片
菜品输出代码 有道智云AI中图片翻译的调用
文章图片
对菜单的扫描翻译

    推荐阅读