陈程的技术博客

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

python 多线程和多进程

2020年6月29日 839点热度 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)
标签聚合
centos js nginx C# winform DevExpress linux python
最新 热点 随机
最新 热点 随机
.NET开发手册标准参考 招募兼职前端开发 Centos安装dotnet6环境 VS上切换分支,vs编译运行出现bug,A fatal error was encountered彻底解决方案 用C#封装一个线程安全的缓存器,达到目标定时定量更新入库 C#通过特性的方式去校验指定数据是否为空
通过tablesorter.js ,table表格快速实现自动排序 用Winform绘制不规则矩形 主程序ui线程异常处理方案和只允许同时运行一个进程的方法 python 发送邮件 C#获取音乐相关信息和相关问题解决 DreamSkin自定义美化控件-RoundButton圆角矩形按钮控件

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

THEME KRATOS MADE BY VTROIS