陈程的技术博客

  • 关于作者
全栈软件工程师
一个专注于技术研究创新的程序员
  1. 首页
  2. python
  3. 正文

python 多线程和多进程

2020年6月29日 1003点热度 0人点赞 0条评论
import os
import cv2
import requests
import json
import base64
import numpy as np
from collections import OrderedDict
from concurrent.futures import ThreadPoolExecutor  # 进程池模块
import time

def getByte(path):
    with open(path, 'rb') as f:
        img_byte = base64.b64encode(f.read())
    img_str = img_byte.decode('ascii')
    return img_str

def GetOcr(image):
    url="http://192.168.62.33:8090/api/tr-run/"
    data = {"img":str(image)}
    res = requests.post(url=url,data=data,timeout=100)
    res.encoding = res.apparent_encoding
    json_str = json.loads(res.content,object_pairs_hook=OrderedDict)
    raw= json_str["data"]["raw_out"]
    value=""
    for item in raw:
        value+=item[1]
    return value

def CutImage(path,savepath,key):
    #a= getByte(path)
    image = cv2.imread(path)
    cropImg = image[440:565,415:1400]
    cv2.imencode('.jpg', cropImg)[1].tofile(savepath)
    name= GetOcr(getByte(savepath))
    try:
        cv2.imencode('.jpg', image)[1].tofile("newimages\\"+str(name)+".jpg")
    except Exception as e:
        print('出现异常:', e)
    print(str(key))


def	main():
    pool = ThreadPoolExecutor(5)
    path = "images\\"
    fileList = os.listdir(path)
    if len(fileList)<=0:
        return

    t0 = time.time()
    for item in fileList:
        pool.submit(CutImage, path+item, "cutimages\\"+str(item),fileList.index(item))
    pool.shutdown(wait=True)
    print("完成裁剪,耗时:")
    print (time.time() - t0)

if __name__ == "__main__":
    main()

 

标签: python 多线程
最后更新:2021年4月2日

博主

全栈工程师,侧重项目技术解决方案规划和开发

打赏 点赞
< 上一篇
下一篇 >

文章评论

取消回复

分类
  • .NET (65)
  • docker (3)
  • linux (12)
  • python (20)
  • web (14)
  • 小程序 (4)
  • 数据库 (2)
  • 未分类 (4)
  • 杂七杂八 (10)
标签聚合
nginx js linux DevExpress python winform C# centos
最新 热点 随机
最新 热点 随机
.NET开发手册标准参考 招募兼职前端开发 Centos安装dotnet6环境 VS上切换分支,vs编译运行出现bug,A fatal error was encountered彻底解决方案 用C#封装一个线程安全的缓存器,达到目标定时定量更新入库 C#通过特性的方式去校验指定数据是否为空
python守护进程--supervisor 使用教程 使用C#把汉字转化为拼音(完整版-GB2312汉字都能转化成功) 在winform窗体上创建一个可以在主窗体上拖动拉伸的panel控件 JsonHelper序列化和反序列化 NPOI读写execl 如何配置log4net,让日志分类记录到不同的日志文件中

COPYRIGHT © 2021 陈程的技术博客. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS