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

相关推荐
算法与双吉汉堡2 小时前
【Nanobot项目笔记】项目架构
python·ai·agent·智能体
kyriewen2 小时前
WebAssembly:前端界的“外挂”,让C++代码在浏览器里跑起来
前端·c++·webassembly
悟空和大王2 小时前
核心 SDK 详细设计文档 (Visual-Render-SDK)
前端
空中海2 小时前
02 状态、Hooks、副作用与数据流
开发语言·javascript·ecmascript
knight_9___2 小时前
LLM工具调用面试篇6
人工智能·python·面试·职场和发展·llm·agent
用户3962691060032 小时前
asyncio + subprocess:Python异步调用外部命令踩坑实录
python
空中海3 小时前
04 React Native工程化、质量、发布与生态选型
javascript·react native·react.js
AI砖家3 小时前
Claude Code Superpowers 安装使用指南:让 AI 编程从“业余”走向“工程化”
前端·人工智能·python·ai编程·代码规范
李白的天不白3 小时前
webpack 与axios 版本冲突问题
前端·webpack·node.js