Python实现人脸识别

直接上代码:

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_location
        print("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实现人脸识别算法

相关推荐
qq_158895411112 小时前
AI 音乐生成完成后,音频 URL 为什么会过期?一套可恢复的交付方案
python·api·ai音乐
Warson_L4 小时前
高性能架构设计
python·go
databook5 小时前
新数据到手,先跑哪几步检查
python·数据分析
czq_26867194875 小时前
Python打卡第46天
开发语言·python
卸任5 小时前
Vibe coding工具使用心得
前端·ai编程
brien96 小时前
为什么模型标称 1M,Google Antigravity 聊到 256K 却突然失忆?我们给它做了个原生行内监控圆环
前端
修炼的dance6 小时前
录屏关键帧间隔多少合适?六档实测,2秒到10秒小了75.6%
前端
Lank_M7 小时前
关键帧从1秒拉到10秒,录屏小87.3%,摄像头小10.8%
前端
补码缩写7 小时前
用 ffprobe 拆录屏,八成字节在 29 个关键帧上
前端
百思不得小李7 小时前
一个复杂的动态表单是如何实现的
前端·设计模式