请问有谁可以把本地图片的SDK的运行OCR代码分享一下吗?

请问有谁可以把本地图片的SDK的运行OCR代码分享一下吗?

展开
收起
真的很搞笑 2023-04-26 23:12:59 190 分享 版权
1 条回答
写回答
取消 提交回答
  • #!/usr/bin/env python

    -- coding: utf-8 --

    import json import ssl import urllib.request import base64

    ENCODING = 'utf-8' def get_img_base64(img_file): with open(img_file, 'rb') as infile: s = infile.read() return base64.b64encode(s).decode(ENCODING)

    headers = { 'Authorization': 'APPCODE 这里填入你的APPcode', # 这里填入你的APPcode 'Content-Type': 'application/json; charset=UTF-8' }

    def demo(): host = 'https://generalpdf.market.alicloudapi.com' path = '/ocrservice/pdf'

    url = host + path
    fileBase64 = r"C:\Users\Administrator\Desktop\H&.pdf"   # 这里填入你要ocr的地址
    img_base64data = get_img_base64(fileBase64)
    data = {"fileBase64": img_base64data}
    
    url = 'https://generalpdf.market.alicloudapi.com/ocrservice/pdf'
    
    try:
        print('data is not null')
        params = json.dumps(data).encode(encoding='UTF8')
        req = urllib.request.Request(url, params, headers)
        r = urllib.request.urlopen(req)
        html =r.read()
        print(html)
        r.close();
        return html.decode("utf8")
    except urllib.error.HTTPError as e:
        print("data error")
        print('code:'+ str(e.code))
        print('message:'+ str(e.read().decode("utf8")))
    

    if name == 'main': demo(),此回答整理自钉群“【官方】阿里云OCR公共云客户交流群”

    2023-04-27 12:20:04
    赞同 展开评论

文字识别技术可以灵活应用于证件文字识别、发票文字识别、文档识别与整理等行业场景,满足认证、鉴权、票据流转审核等业务需求。

热门讨论

热门文章

还有其他疑问?
咨询AI助理