.a

在使用Python进行系统管理时,特别是同时操作多个文件目录或者远程控制多台主机,并行操作可以节约大量的时间。如果操作的对象数目不大时,还可以直接使用Process类动态的生成多个进程

,十几个还好,但是如果上百个甚至更多,那手动去限制进程数量就显得特别的繁琐,此时进程池就派上用场了。

Pool类可以提供指定数量的进程供用户调用,当有新的请求提交到Pool中时,如果池还没有满,就会创建一个新的进程来执行请求。如果池满,请求就会告知先等待,直到池中有进程结束,才会创建新的进程来执行这些请求。

import os
import face_recognition
from multiprocessing.dummy import Pool pool = Pool(8) # 启动进程池 def helloface(known_face_encodings, known_face_names, unknown_pic):
"""
单个图片识别
:param known_face_encodings: single known img's encodings
:param known_face_names: all names, >> list
:param unknown_pic: single unknown img's path
:return: face result >>name
"""
name = "Unknown"
unknown_image = face_recognition.load_image_file(unknown_pic)
face_locations = face_recognition.face_locations(unknown_image) # box size?
face_encodings = face_recognition.face_encodings(unknown_image, face_locations)
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
matches = face_recognition.compare_faces(known_face_encodings, face_encoding, tolerance=0.39)
if True in matches:
first_match_index = matches.index(True)
name = known_face_names[first_match_index]
else:
name = "Unknown"
return name def faceRecog(imglist, known_face_names, unknownpath):
"""
:param imglist: [list known img address]
:param known_face_names: all known names
:param unknownpath: single unknownpath
:return: The name of the identification And index in names
"""
   ## pool.map(func, iter)
known_face_encodings = pool.map(mutl_reg, imglist) # 返回已知图片encodings, list
name = "Unknown"
first_match_index = "notMatch"
unknown_image = face_recognition.load_image_file(unknownpath)
face_locations = face_recognition.face_locations(unknown_image)
face_encodings = face_recognition.face_encodings(unknown_image, face_locations)
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
matches = face_recognition.compare_faces(known_face_encodings, face_encoding, tolerance=0.39)
# print(matches, "--------------------------")
if True in matches:
first_match_index = matches.index(True)
name = known_face_names[first_match_index]
return name, first_match_index
else:
return name, first_match_index def mutl_reg(imglist):
"""
:param imglist: known img paths, >> list
:return: known img's encodings, >> list
"""
obama_image = face_recognition.load_image_file(imglist)
known_face_encodings = face_recognition.face_encodings(obama_image)[0]
return known_face_encodings def get_all_path(path='./known/'):
"""
获取指定路径下的文件的url, note: path下最好没有其他的目录
:param path: 指定路径
:return: 改路径下的地址
"""
all_files = os.walk(path)
files_dir = []
for i, v, files in all_files:
for file in files:
files_dir.append(os.path.join(path, file))
return files_dir def faceRecogUnknownList(known_img_list, names, unknownpaths):
""" """
result = []
for unknownpath in unknownpaths:
name, index = faceRecog(known_img_list, names, unknownpath)
# if index != 'notMatch':
result.append({name: unknownpath, 'index': index})
result.append(name)
print('It is [%s] to identify the [%s] through a face' % (name, unknownpath)) return result if __name__ == '__main__': # known_face_pic = face_recognition.load_image_file('./known/Comi.jpg')
# known_face_encodings = face_recognition.face_encodings(known_face_pic)
# name = 'Comi'
# unknown_pic_path = './unknown/unknown1.jpg'
# name = helloface(known_face_encodings, [name,], unknown_pic_path)
# print(name) known_img_list = get_all_path('./known/')
names = ['Obama', 'Comi', 'Bidden']
unknownpaths = get_all_path('./unknown/') result = faceRecogUnknownList(known_img_list, names, unknownpaths)
print(result)

face,Pool的更多相关文章

  1. Process类,Thread类,Pool类,gevent类,ProcessPoolExecutor,ThreadPoolExecutor的用法比较

    一 Process类 multiprocessing模块下的一个类 创建子进程. 有两种方法 方法一 from multiprocessing import Process import os def ...

  2. 0704 Process继承实现多进程、Pool进程池,进程间通过队列通信,Pool实现多进程实现复制文件

    通过继承的方式,实现Process多进程 from multiprocessing import Process import time class MyNewProcess(Process): de ...

  3. socket阻塞与非阻塞,同步与异步,select,pool,epool

    概念理解 一.与I/O相关的五个重要概念 1. 第一个概念:用户空间与内核空间 1. 现在操作系统都是采用虚拟存储器,那么对32位操作系统而言,它的寻址空间(虚拟存储空间)为4G(2的32次方) 2. ...

  4. 创建,查看,删除pool,查看,修改pool参数命令总结

    标签(空格分隔): ceph,ceph运维,pool 1. 创建pool命令: ceph的pool有两种类型,一种是副本池,一种是ec池,创建时也有所区别 1.1 创建副本池: $ sudo ceph ...

  5. 黑马程序员-autorelease pool

    Autorelease:可以延迟给对象发送release消息.发送一个autorelease消息给对象,证明该对象在一定时间内有效,一定时间后会对该对象进行释放,进行一次release. 一个auto ...

  6. 【hbase】——Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询

    1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...

  7. retain,copy,assign及autorelease ,strong,weak

    一,retain, copy, assign区别 1. 假设你用malloc分配了一块内存,并且把它的地址赋值给了指针a,后来你希望指针b也共享这块内存,于是你又把a赋值给(assign)了b.此时a ...

  8. redis pool config的配置参数

    .获取jedis实例时,实际上可能有两类错误.一类是pool.getReource(),得不到可用的jedis实例:另一类是jedis.set/get时出错也会抛出异常:为了实现区分,所以根据inst ...

  9. (转)Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询

    1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...

随机推荐

  1. Adobe Flash Player - imsoft.cnblogs

    Adobe Flash Player是一个跨平台.基于浏览器的应用程序.运行时,它可以跨屏幕和浏览器原汁原味地查看具有表现力的应用程序.内容和视频.Flash Player实现了移动屏幕上的高性能优化 ...

  2. 最短路--spfa+队列优化模板

    spfa普通版就不写了,优化还是要的昂,spfa是可以判负环,接受负权边和重边的,判断负环只需要另开一个数组记录每个结点的入队次数,当有任意一个结点入队大于点数就表明有负环存在 #include< ...

  3. Linux下rsync命令使用总结

    一.rsync的概述 rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync.rsync是Linux系统下的文件同步和数据传输工具,它采用“rsync” ...

  4. jquery选择器总结2

    1.JQuery的概念 JQuery是一个JavaScript的类库,这个类库集合了很多功能方法,利用类库你可以用一些简单的代码实现一些复杂的JS效果. 2.JQuery实现了 代码的分离 不用再网页 ...

  5. test20190320 全连(fc)

    题意 全连(fc) [题目背景] 还记得若干年前那段互相比较<克罗地亚狂想曲>的分数的日子吗? [题目描述] E.Space 喜欢打音游. 但是他技术不好,总是拿不到全连(Full Com ...

  6. signal()信号操作

    一.函数描述 #include <signal.h> typedef void (*sighandler_t)(int);sighandler_t signal(int signum, s ...

  7. thrift 知识点

    mac下,thrift 安装 mac下,最简单安装thrift的方法:使用brew安装 brew update brew install thrift 验证安装成功:thrift --help 安装出 ...

  8. ionic3之自定义tabs菜单图标

    请参考以下链接 ionic3之自定义tabs菜单图标

  9. mySQL 教程 第5章 插入 更新与删除数据

    使用SQL Manager管理工具连接到schoolDB.由于三张表都设置了主键,因此,以下练习中插入的记录,主键不能重. 插入数据 1. 练习:为表的所有字段插入数据 为表中所有字段插入数据,可以不 ...

  10. VBox修改uuid

    1.使用VBoxManage命令时,需要先在命令行中切换到VirtualBox的安装目录下 2.修改vdi的uuid:VBoxManage internalcommands sethduuid  D: ...