重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇内容介绍了“Python怎么实现识别图片中的所有人脸并显示出来”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
业务包括:企业网站建设、移动网站建设、商城网站制作、网站营销推广等服务,并且涵盖域名与空间、雅安服务器托管、云服务器、等互联网基础服务;创新互联公司联建站以互联网的创新理念,成熟完善的建站体系,开拓进取的精神,专业的解决方案和顾问咨询服务,帮助客户在互联网时代提升形象、把握商机、实现价值,提高企业的核心竞争力。
使用Python3实现识别图片中的所有人脸并显示出来,代码如下:
# -*- coding: utf-8 -*- # 识别图片中的所有人脸并显示出来 # filename : find_faces_in_picture.py from PIL import Image import face_recognition # 将jpg文件加载到numpy 数组中 image = face_recognition.load_image_file("linuxidc.com.jpg") # 使用默认的给予HOG模型查找图像中所有人脸 # 这个方法已经相当准确了,但还是不如CNN模型那么准确,因为没有使用GPU加速 # 另请参见: find_faces_in_picture_cnn.py face_locations = face_recognition.face_locations(image) # 使用CNN模型 # face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn") # 打印:我从图片中找到了 多少 张人脸 print("I found {} face(s) in this photograph.".format(len(face_locations))) # 循环找到的所有人脸 for face_location in face_locations: # 打印每张脸的位置信息 top, right, bottom, left = face_location print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right)) # 指定人脸的位置信息,然后显示人脸图片 face_image = image[top:bottom, left:right] pil_image = Image.fromarray(face_image) pil_image.show()
# 或者执行python文件 $ python3 www.linuxidc.com.py
从图片中识别出10张人脸,并显示出来。
I found 10 face(s) in this photograph. A face is located at pixel location Top: 445, Left: 1867, Bottom: 534, Right: 1957 A face is located at pixel location Top: 544, Left: 643, Bottom: 619, Right: 718 A face is located at pixel location Top: 478, Left: 1647, Bottom: 553, Right: 1722 A face is located at pixel location Top: 504, Left: 126, Bottom: 594, Right: 215 A face is located at pixel location Top: 536, Left: 395, Bottom: 611, Right: 469 A face is located at pixel location Top: 544, Left: 1042, Bottom: 619, Right: 1116 A face is located at pixel location Top: 553, Left: 818, Bottom: 627, Right: 892 A face is located at pixel location Top: 511, Left: 1431, Bottom: 586, Right: 1506 A face is located at pixel location Top: 564, Left: 1227, Bottom: 626, Right: 1289 A face is located at pixel location Top: 965, Left: 498, Bottom: 1017, Right: 550
如下图:
“Python怎么实现识别图片中的所有人脸并显示出来”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!