SVM深入理解&人脸特征提取(二)

人脸特征提取

绘制特征点

import numpy as np
import cv2
import dlib
import os
import sys
import random

# dlib预测器
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('D:\date\shape_predictor_68_face_landmarks.dat')

ok = True
# 打开摄像头 参数为输入流,可以为摄像头或视频文件
camera = cv2.VideoCapture(0)
#camera = cv2.VideoCapture('video.mp4')
while ok:
    # 读取摄像头中的图像,ok为是否读取成功的判断参数
    ok, img = camera.read()

    # 转换成灰度图像
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    rects = detector(img_gray, 0)
    for i in range(len(rects)):
        landmarks = np.matrix([[p.x, p.y] for p in predictor(img, rects[i]).parts()])
        # 矩阵转为列表
        point_list=landmarks.getA()

        # 点坐标
        point_37 = (point_list[37][0],point_list[37][1])
        point_38 = (point_list[38][0], point_list[38][1])

        # 比例系数,37,38两点距离
        size = (pow(pow(point_38[1] - point_37[1], 2) + pow(point_38[0] - point_37[0], 2), 0.5))

        # 点坐标
        point_39 = (point_list[39][0], point_list[39][1])
        point_42 = (point_list[42][0], point_list[42][1])

        # 画特征点
        for idx, point in enumerate(landmarks):
            # 68点的坐标
            pos = (point[0, 0], point[0, 1])

            # 利用cv2.circle给每个特征点画一个圈,共68个
            cv2.circle(img, pos, 1, color=(0, 255, 0))

            # 利用cv2.putText输出1-68
            font = cv2.FONT_HERSHEY_SIMPLEX
            cv2.putText(img, str(idx + 1), pos, font, 0.3, (0, 0, 255), 1, cv2.LINE_AA)
    cv2.imshow('video', img)
    k = cv2.waitKey(1)
    if k == 27:  # 按下ESC退出
        break
camera.release()
cv2.destroyAllWindows()



运行
在这里插入图片描述

墨镜特效

import numpy as np
import cv2
import dlib
import os
import sys
import random

# dlib预测器
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('D:\data\shape_predictor_68_face_landmarks.dat')

ok = True
# 打开摄像头 参数为输入流,可以为摄像头或视频文件
camera = cv2.VideoCapture(0)
#camera = cv2.VideoCapture('D:/video.mp4')
while ok:
    # 读取摄像头中的图像,ok为是否读取成功的判断参数
    ok, img = camera.read()

    # 转换成灰度图像
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    rects = detector(img_gray, 0)
    for i in range(len(rects)):
        landmarks = np.matrix([[p.x, p.y] for p in predictor(img, rects[i]).parts()])
        # 矩阵转为列表
        point_list=landmarks.getA()

        # 点坐标
        point_37 = (point_list[37][0],point_list[37][1])
        point_38 = (point_list[38][0], point_list[38][1])

        # 比例系数,37,38两点距离
        size = (pow(pow(point_38[1] - point_37[1], 2) + pow(point_38[0] - point_37[0], 2), 0.5))

        # 点坐标
        point_39 = (point_list[39][0], point_list[39][1])
        point_42 = (point_list[42][0], point_list[42][1])

        cv2.circle(img, (point_list[41][0], point_list[41][1]), int(3 * size), (0, 0, 0), -1)
        cv2.circle(img, (point_list[46][0], point_list[46][1]), int(3 * size), (0, 0, 0), -1)
        # 画眼镜框
        cv2.line(img, point_39, point_42, (0, 0, 0), 4)

    cv2.imshow('video', img)
    k = cv2.waitKey(1)
    if k == 27:  # 按下ESC退出
        break
camera.release()
cv2.destroyAllWindows()

运行
在这里插入图片描述

总结

优点:
1、非接触性,相比较其他生物识别技术而言,人脸识别是非接触的,用户不需要和设备直接接触。
2、并发性,在实际应用场景中,人脸识别技术可以进行多个人脸的分拣、判断及识别。
3、非强制性,被识别的人脸图像信息可以主动获取而不被被测个体察觉。
4、自然性,所谓的自然性是指通过观察比较人脸来区分和确认身份;具有自然性的识别还有语音识别和体形识别。
缺点:
1、人类脸部存在相似性,不同个体之间的区别不大,所有的人脸的结构都相似,甚至人脸器官的结构外形都很相似。这样的特点对于利用人脸进行定位是有利的,但是对于利用人脸区分人类个体是不利的。在加上化妆的掩盖及双胞胎的天然相似性更增加了识别的难度。
2、人脸存在易变性,人脸的外形很不稳定,人可以通过脸部的变化产生很多表情,而在不同观察角度,人脸的视觉图像也相差很大。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值