日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用多线程的方式调用chineseocr_API

發布時間:2023/12/13 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用多线程的方式调用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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。