python dlib实现小程序(1)检测视频中人脸的64个点


python dlib实现小程序(1)检测视频中人脸的64个点
【python dlib实现小程序(1)检测视频中人脸的64个点】

# coding=utf-8 import sys import dlib import cv2 as cv import oscurrent_path = os.getcwd() #获取当前路径 path = current_path + "\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,Bdets = detector(fame2,1)#使用detector进行人脸检测for index,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),1)cv.imshow("renlian",fame)k = cv.waitKey(10) if k & 0xff == ord('q'): break cap.release() cv.destroyAllWindows()

实现效果如下:
python dlib实现小程序(1)检测视频中人脸的64个点
文章图片

原PO:
https://blog.csdn.net/hongbin_xu/article/details/78348086

    推荐阅读