wvinzh / baiduocr_demo Goto Github PK
View Code? Open in Web Editor NEWBaiduOCR_Demo
BaiduOCR_Demo
以下是官方的API调用范例:
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.