使用多线程的方式调用chineseocr_API
生活随笔
收集整理的這篇文章主要介紹了
使用多线程的方式调用chineseocr_API
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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())識別結果
問題
- 容易出現錯誤,時間提高性能不大
總結
以上是生活随笔為你收集整理的使用多线程的方式调用chineseocr_API的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: openssl里面AES算法主要函数的参
- 下一篇: 算法考题 替换空格