dlib +python+cv 简单实现人脸64关键点检测

# _*_ coding:utf-8 _*_
# coding=utf-8
import sys
import dlib
import cv2 as cv
import os

path = r"/home/xiaou/Downloads/python_spoof/shape_predictor_68_face_landmarks.dat"

detector = dlib.get_frontal_face_detector()  #获取人脸分类器
predector = dlib.shape_predictor(path) #获取人脸检测器

cap = cv.VideoCapture(0)

while True:
    ret, fame = cap.read()
    if ret is True:
        b,g,r =cv.split(fame) #分离色道 opencv读入的色道是B,G,R
        fame2 = cv.merge([r,g,b]) #合成R,G,B
        dets = detector(fame2,1)#使用detector进行人脸检测
    for i,face in enumerate(dets):#遍历返回值 index是几个人脸
        shape = predector(fame2,face) #寻找人脸的68个脸

        for index,pt in enumerate(shape.parts()):#遍历所有的点,把点用蓝色的圈圈表示出来
            pt_pox = (pt.x,pt.y)
            cv.circle(fame,pt_pox,2,(255,0,0),2)

    cv.imshow("me",fame)

    k = cv.waitKey(10)
    if k & 0xff == ord('q'):
        break
cap.release()
cv.destroyAllWindows()

效果如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值