陈程的技术博客

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

python 多线程和多进程

2020年6月29日 588点热度 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)
标签聚合
C# nginx python linux winform centos js DevExpress
最新 热点 随机
最新 热点 随机
.NET开发手册标准参考 招募兼职前端开发 Centos安装dotnet6环境 VS上切换分支,vs编译运行出现bug,A fatal error was encountered彻底解决方案 用C#封装一个线程安全的缓存器,达到目标定时定量更新入库 C#通过特性的方式去校验指定数据是否为空
C# 一个发送邮件的帮助类 DreamSkin自定义美化控件-带智能下拉提示的TextBox控件 关于使用webBrowser操作HTML的帮助类 一个对缓存操作的类DataCache 用Winform绘制不规则矩形 机器学习目标检测之印章检测和分类

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

THEME KRATOS MADE BY VTROIS