Skip to content

Instantly share code, notes, and snippets.

@quxiao
Created August 3, 2018 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quxiao/2e19f1a772892375c81e8622a1e59d01 to your computer and use it in GitHub Desktop.
Save quxiao/2e19f1a772892375c81e8622a1e59d01 to your computer and use it in GitHub Desktop.
import os
import sys
import base64
import requests
import json
# config host address
HOST = "http://localhost:10000"
def main():
num_pass = 0
num_fail = 0
with open("./groundtruth.json",'r') as gt_file:
files = json.load(gt_file)
for f in files:
print(f["filename"])
byimage = b"data:application/octet-stream;base64," + base64.b64encode(open('./imgs/'+f["filename"]).read())
headers = {"Content-Type": "application/json", "Authorization": "QiniuStub uid=1&ut=2"}
r = requests.post(HOST + "/v1/ocr/text", headers=headers, data=json.dumps({"data":{"uri":byimage.decode('utf8')}}))
print r.text
r = json.loads(r.text)
if json.dumps(r["result"]) == json.dumps(f["result"]):
print('test file ' + f["filename"] + ': pass')
num_pass += 1
else:
print('test file ' + f["filename"] + ': failed')
num_fail += 1
print()
print(str(num_pass) + ' pass')
print(str(num_fail) + ' failed')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment