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

相关推荐

  1. 人脸识别Python实现】PyQt5人脸识别管理系统

    2024-07-16 15:36:03       21 阅读
  2. 基于python实现人脸识别登录系统

    2024-07-16 15:36:03       42 阅读
  3. Python实现人脸识别系统

    2024-07-16 15:36:03       30 阅读
  4. face_recognition+python-opencv实现摄像头实时人脸识别

    2024-07-16 15:36:03       32 阅读
  5. python 人脸检测与人脸识别

    2024-07-16 15:36:03       45 阅读
  6. opencv实现视频人脸识别

    2024-07-16 15:36:03       41 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-16 15:36:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-16 15:36:03       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-16 15:36:03       58 阅读
  4. Python语言-面向对象

    2024-07-16 15:36:03       69 阅读

热门阅读

  1. 观察者模式:构建响应式系统的基石

    2024-07-16 15:36:03       25 阅读
  2. 日常学习--Linux命令梳理--20240715

    2024-07-16 15:36:03       20 阅读
  3. Scala学习笔记17: Try与异常处理

    2024-07-16 15:36:03       22 阅读
  4. 全局变量 y1 会和 cmath 标准库中的变量产生冲突

    2024-07-16 15:36:03       19 阅读
  5. Solus Linux简介

    2024-07-16 15:36:03       22 阅读
  6. 0基础学python-8:if,while,for

    2024-07-16 15:36:03       23 阅读
  7. RPC 的原理和示例

    2024-07-16 15:36:03       24 阅读
  8. Log4j的原理及应用详解(三)

    2024-07-16 15:36:03       24 阅读