forked from chineseocr/chineseocr
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a673fc
commit f2fd9c2
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@author: lywen | ||
后台通过接口调用服务,获取OCR识别结果 | ||
""" | ||
import base64 | ||
import requests | ||
import json | ||
def read_img_base64(p): | ||
with open(p,'rb') as f: | ||
imgString = base64.b64encode(f.read()) | ||
imgString=b'data:image/jpeg;base64,'+imgString | ||
return imgString.decode() | ||
|
||
def post(p,billModel='通用OCR'): | ||
URL='http://127.0.0.1:8080/ocr'##url地址 | ||
imgString = read_img_base64(p) | ||
headers = {} | ||
param = {'billModel':billModel,##目前支持三种 通用OCR/ 火车票/ 身份证/ | ||
'imgString':imgString,} | ||
param = json.dumps(param) | ||
if 1: | ||
req = requests.post(URL,data= param,headers=None,timeout=5) | ||
data = req.content.decode('utf-8') | ||
data = json.loads(data) | ||
else: | ||
data =[] | ||
print(data) | ||
|
||
|
||
if __name__=='__main__': | ||
p = 'test/card.png' | ||
post(p,'身份证') |