!! !" #$%&%% '%
()% ! " #$%&%%
'%((级联器方法)
(
$$$*!(+,*!(数据集训练方法)
(* 关键点实时监测)
#_*_coding:utf-8_*_
importnumpyasnp
importcv2
importdlib
cap=cv2.VideoCapture(0)
detector=dlib.get_frontal_face_detector()
predictor=dlib.shape_predictor("E:\Python-3.8.2\Lib\site-
packages\face_recognition_models\
shape_predictor_68_face_landmarks.dat")
#这个是需要自己下的
while1:
ret,img=cap.read()
#取灰度
img_gray=cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
#人脸数 rects
rects=detector(img_gray,0)
foriinrange(len(rects)):
landmarks=np.matrix([[p.x,p.y]forpinpredictor(img,
rects[i]).parts()])
foridx,pointinenumerate(landmarks):
#68 点的坐标
pos=(point[0,0],point[0,1])
#利用 cv2.circle 给每个特征点画一个圈,共 68 个
cv2.circle(img,pos,2,color=(0,255,0))
#利用 cv2.putText 输出 1-68
font=cv2.FONT_HERSHEY_SIMPLEX