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

相关推荐
css趣多多10 分钟前
案例自定义tabBar
前端
xinxiyinhe22 分钟前
如何设置Cursor中.cursorrules文件
人工智能·python
诸神缄默不语1 小时前
如何用Python 3自动打开exe程序
python·os·subprocess·python 3
橘子师兄1 小时前
分页功能组件开发
数据库·python·django
Logintern092 小时前
使用VS Code进行Python编程的一些快捷方式
开发语言·python
林的快手2 小时前
CSS列表属性
前端·javascript·css·ajax·firefox·html5·safari
Multiple-ji2 小时前
想学python进来看看把
开发语言·python
匹马夕阳2 小时前
ECharts极简入门
前端·信息可视化·echarts
bug总结2 小时前
新学一个JavaScript 的 classList API
开发语言·javascript·ecmascript
liuyuzhongcc2 小时前
List 接口中的 sort 和 forEach 方法
java·数据结构·python·list