ChineseOCR在线API
界面
- 提供多种接口调用方式,比如在线调用、Javascript api调用、curl api调用和python api调用四种方式,本次使用javascript api调用的方式进行OCR识别
代码
import glob
import base64
import os
import requests
import threading
import time
from time import ctimeWSI_MASK_PATH = 'E:\\OCRTest'#存放图片的文件夹路径
paths = glob.glob(os.path.join(WSI_MASK_PATH, '*.jpg'))
print(paths)
print("******************************************************************")base_url = "https://momodel.cn/pyapi/apps/run/"
app_id = "5cd04ee51afd94639a492b8e"
app_version = "0-2-0"def read_file(filpos,i):with open(filpos+str(i)+".jpg","rb")as f:data = f.read()encoder = base64.b64encode(data)# print(str(encoder,'utf-8'))fill_with_base64_image = str(encoder, 'utf-8')input_dic = {"img": {"val": fill_with_base64_image, "type": "img"}}output_dic = {"take_time": {"type": "float"}, "output": {"type": "str"}}payload = {"app": {"input": input_dic, "output": output_dic}, "version": app_version}response = requests.post(base_url + app_id, json=payload)print(response.json())threads = []
x=0
for t in range(0,3):t= threading.Thread(target=read_file,args=("E:\\OCRTest\\",x))threads.append(t)time.sleep(10)x+=1#join在里面时候只有第一个子进程结束才能打开第二个进程,if__name__ 调用时不可用
if __name__=="__main__":for thr in threads:thr.start()thr.join()print("all over %s"%ctime())
识别结果
问题