dlib人脸特征库分类器,81个点 包含使用代码,通过摄像头识别人脸
import cv2
import dlib
from skimage import io
import numpy as np
# 使用特征提取器get_frontal_face_detector
detector = dlib.get_frontal_face_detector()
# dlib的68点模型,使用作者训练好的特征预测器
predictor = dlib.shape_predictor("shape_predictor_81_face_landmarks.dat")
cap=cv2.VideoCapture(0)
while True:
ret,img=cap.read()
dets = detector(img, 1)
for k, d in enumerate(dets):
print("第", k+1, "个人脸d的坐标:",
"left:", d.left(),
"right:", d.right(),
"top:", d.top(),
"bottom:", d.bottom())
width = d.right() - d.left()
heigth = d.bottom() - d.top()
print('人脸面积为:',(width*heigth))
# 利用预测器预测
#shape = predictor(img, d)
cv2.rectangle(img,(d.left(),d.top()),(d.right(),d.bottom()),(0,255,0),1)
shape = predictor(img, d)
landmarks = np.matrix([[p.x, p.y] for p in shape.parts()])
for num in range(shape.num_parts):
cv2.circle(img, (shape.parts()[num].x, shape.parts()[num].y), 3, (0,255,0), -1)
#cv2.putText(img, str(i), (shape.part(i).x, shape.part(i).y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255))
cv2.imshow("img",img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
1