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

相关推荐
Learn Beyond Limits2 分钟前
Data Mining Tasks|数据挖掘任务
人工智能·python·神经网络·算法·机器学习·ai·数据挖掘
韩立学长5 分钟前
【开题答辩实录分享】以《证劵数据可视化分析项目设计与实现》为例进行答辩实录分享
python·信息可视化·vue
蓝桉~MLGT11 分钟前
Python学习历程——模块
开发语言·python·学习
庙堂龙吟奈我何24 分钟前
js中哪些数据在栈上,哪些数据在堆上?
开发语言·javascript·ecmascript
知忆_IS27 分钟前
【问题解决】Label Studio上传文件数量超限解决方案
python·目标检测·label studio
二川bro28 分钟前
第30节:大规模地形渲染与LOD技术
前端·threejs
武子康29 分钟前
Java-169 Neo4j CQL 实战速查:字符串/聚合/关系与多跳查询
java·开发语言·数据库·python·sql·nosql·neo4j
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ37 分钟前
MyBatis Plus中执行原生SQL语句方法
python·sql·mybatis