陈程的技术博客

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

python 多线程和多进程

2020年6月29日 1144点热度 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)
  • 未分类 (3)
  • 杂七杂八 (11)
标签聚合
js nginx python DevExpress centos linux C# winform
最新 热点 随机
最新 热点 随机
965公司招聘内推!由半导体芯片相关行业经验来,福利好不加班对年龄学历友好放宽,欢迎来投 .NET开发手册标准参考 Centos安装dotnet6环境 VS上切换分支,vs编译运行出现bug,A fatal error was encountered彻底解决方案 用C#封装一个线程安全的缓存器,达到目标定时定量更新入库 C#通过特性的方式去校验指定数据是否为空
965公司招聘内推!由半导体芯片相关行业经验来,福利好不加班对年龄学历友好放宽,欢迎来投
C# 采用Automation控制自动化操作第三方软件 C#通过特性的方式去校验指定数据是否为空 用Winform绘制不规则矩形 Centos安装dotnet6环境 drools开源规则引擎部署方案-在centos的docker部署 网页连接调起本地应用,注册表写入

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

THEME KRATOS MADE BY VTROIS