《One Millisecond Face Alignment with an Ensemble of Regression Trees》学习笔记(一)---环境布置及代码实现

  “One Millisecond Face Alignment with an Ensemble of Regression Trees”使用归一法实现人脸特征检测,测试基准下达到99.38%。python中DLIB提供了各种使用方法(https://github.com/ageitgey/face_recognition#face-recognition)。

出现如下界面:
在这里插入图片描述

继续输入:.\b2 回车 (我编译时长1个小时)
在这里插入图片描述
③安装cmake
https://cmake.org/download/
进入如下页面:
在这里插入图片描述

接下来安装进入如下界面:
在这里插入图片描述
选择 Add CMake to the system PATH for all users
④安装DLIB
http://dlib.net/
在这里插入图片描述

解压后,重新打开cmd界面内,进入dlib的解压目录,输入:python setup.py install,也可通过Anaconda命令实现:
在这里插入图片描述

在这里插入图片描述
⑤安装face_recognition
pip install face_recognition
也可下载后安装
进入编辑器检验后,确定安装完成。

2.代码实现

import face_recognition
import cv2

# video_capture = cv2.VideoCapture(0)  #摄像头获取视频
cap = cv2.VideoCapture(r"D:\Xu\other\S01E01.mp4")  #本地获取视频
# 本地图像
hhj_image = face_recognition.load_image_file(r"D:\Xu\SIFT\faceT\timg111.jpg")
hhj_face_encoding = face_recognition.face_encodings(hhj_image)[0]


face_locations = []
face_encodings = []
face_names = []
process_this_frame = True



while True:
    # 读取视频画面
    # ret, frame = video_capture.read(r"D:\Xu\other\S01E01.mp4")

    ret, frame = cap.read()
    # 改变摄像头图像的大小,图像小,所做的计算就少
    small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

    # opencv的图像是BGR格式的,而我们需要是的RGB格式的,因此需要进行一个转换。
    rgb_small_frame = small_frame[:, :, ::-1]

    # Only process every other frame of video to save time
    if process_this_frame:
        # 根据encoding来判断是不是同一个人,是就输出true,不是为flase
        face_locations = face_recognition.face_locations(rgb_small_frame)
        face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)

        face_names = []
        for face_encoding in face_encodings:
            # 默认为unknown
            match = face_recognition.compare_faces([hhj_face_encoding], face_encoding)
            name = "Unknown"

            if match[0]:
                name = "Feib"

            face_names.append(name)

    process_this_frame = not process_this_frame

    # 将捕捉到的人脸显示出来
    for (top, right, bottom, left), name in zip(face_locations, face_names):
        # Scale back up face locations since the frame we detected in was scaled to 1/4 size
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4

        # 矩形框
        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

        #加上标签
        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
        font = cv2.FONT_HERSHEY_DUPLEX
        cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)

    # Display
    cv2.imshow('Video', frame)

    # 按Q退出
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值