欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 手游 > Python实现人脸识别

Python实现人脸识别

2024/10/24 4:45:21 来源:https://blog.csdn.net/jlq_diligence/article/details/140411575  浏览:    关键词:Python实现人脸识别

直接上代码:

import face_recognition
import time
from PIL import Image, ImageDraw
def faceRecognition(fileName):  # 加载图片image = face_recognition.load_image_file(fileName)# 人脸定位beginTime = time.time()face_locations = face_recognition.face_locations(image)image2 = Image.open(fileName)pil_image = ImageDraw.Draw(image2)for face_location in face_locations:# 打印位置top, right, bottom, left = face_locationprint("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))# 红色的边框颜色red_color =(255, 0, 0)# 边框的宽度border_width = 3# 要画红框的坐标 (x, y, x+width, y+height)box_coordinates = (left, top, right, bottom)# 画红框pil_image.rectangle(box_coordinates, width=border_width, outline=red_color)# 人脸图# face_image = image[top:bottom, left:right]# pil_image = Image.fromarray(face_image)# pil_image.show()image2.show()if __name__ == '__main__':faceRecognition('10010.jpg')

运行效果为:

完整代码地址:Python实现人脸识别算法

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com