代码拉取完成,页面将自动刷新
同步操作将从 celaraze/any-to-excel 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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
# OCR识别封装
class OCR(object):
def img_to_excel(self,
output_file_name,
image_path,
secret_id,
secret_key):
# 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
cred = credential.Credential(
secret_id,
secret_key
)
# 实例化client对象
httpProfile = HttpProfile()
httpProfile.endpoint = "ocr.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
clientProfile.signMethod = "TC3-HMAC-SHA256"
client = ocr_client.OcrClient(cred, "ap-shanghai", clientProfile)
# 实例化一个请求对象
req = models.GeneralFastOCRRequest()
# 读取图片数据,使用Base64编码
with open(image_path, 'rb') as f:
image = f.read()
image_base64 = str(base64.b64encode(image), encoding='utf-8')
req.ImageBase64 = image_base64
# 通过client对象调用访问接口,传入请求对象
resp = client.TableOCR(req)
# 获取返回数据(Data为Base64编码后的Excel数据)
data = resp.Data
# 转换为Excel
output_file_name = str(output_file_name)
path_excel = output_file_name+".xlsx"
with open(path_excel, 'wb') as f:
f.write(base64.b64decode(data))
return path_excel
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。