人脸landmarks在人脸分析上有很大的作用,可以利用landmarkers进行人脸校正(alignment),也可以通过landmarkers计算五官之间的距离来对人脸建模,判断美丑等。
dlib(/)提供了很友好的检测人脸landmarkers的接口。下图是一个68个点的landmarkers检测结果,可以通过数字对应到五官,例如27~30是检测鼻子区域的。
检测代码如下:
img_path = 'data/face_one.png'img = cv2.imread(img_path)print('img_shape:', img.shape)img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)# get facehog_face_detector = dlib.get_frontal_face_detector()shape_predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')rects, scores, idx = hog_face_detector.run(img_rgb, 2, 0)faces = dlib.full_object_detections()for rect in rects:faces.append(shape_predictor(img_rgb, rect))for landmark in faces:for idx, point in enumerate(landmark.parts()):cv2.putText(img, str(idx), (point.x, point.y), cv2.FONT_HERSHEY_DUPLEX, 0.3, (0, 0, 255), 1, cv2.LINE_AA)
代码比较简单,首先用dlib的frontal_face_detector检测人脸区域,然后dlib的shape_predictor检测出各个点的位置。
如果觉得《dlib检测人脸landmarks》对你有帮助,请点赞、收藏,并留下你的观点哦!