Code Monkey home page Code Monkey logo

baiduocr_demo's People

Contributors

wvinzh avatar

Stargazers

 avatar

Watchers

 avatar  avatar

baiduocr_demo's Issues

麻烦问下,我想批量调用baidu iocr模版怎么实现啊。

以下是官方的API调用范例:

-- coding:UTF-8 --

-- encoding: utf-8 --

import base64
import requests

if sys.version_info.major == 2:
from urllib import quote
else:
from urllib.parse import quote

headers = {
'Content-Type': "application/x-www-form-urlencoded",
'charset': "utf-8"
}
if name == 'main':
# 代码中所需的工具包requests
# 安装方式:pip install requests
# iocr识别api_url
recognise_api_url = "https://aip.baidubce.com/rest/2.0/solution/v1/iocr/recognise/finance"

access_token = "your_access_token"
templateSign = "your_templateSign"
detectorId = 0
classifierId = "your_classifier_id"
# 测试数据路径
image_path = "your_file_path"
try:
    with open(image_path, 'rb') as f:
        image_data = f.read()
    
    if sys.version_info.major == 2:
        image_b64 = base64.b64encode(image_data).replace("\r", "")
    else:
        image_b64 = base64.b64encode(image_data).decode().replace("\r", "")
    
    # 请求模板的bodys
    recognise_bodys = "access_token=" + access_token + "&templateSign=" + templateSign + \
            "&image=" + quote(image_b64.encode("utf8"))
    # 请求分类器的bodys
    classifier_bodys = "access_token=" + access_token + "&classifierId=" + classifierId + \
            "&image=" + quote(image_b64.encode("utf8"))
    # 请求模板识别
    response = requests.post(recognise_api_url, data=recognise_bodys, headers=headers)
    # 请求分类器识别
    # response = requests.post(recognise_api_url, data=classifier_bodys, headers=headers)
    print response.text
except Exception as e:
    print e

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.