face_landmark_point

import cv2
import dlib
import numpy
import sys

PREDICTOR_PATH = “shape_predictor_81_face_landmarks.dat”
#1.使用dlib自带的frontal_face_detector作为我们的人脸提取器
detector = dlib.get_frontal_face_detector()
#2.使用官方提供的模型构建特征提取器
predictor = dlib.shape_predictor(PREDICTOR_PATH)
class NoFaces(Exception):
pass
im = cv2.imread(“1.jpg”)
#3.使用detector进行人脸检测 rects为返回的结果
rects = detector(im,1)
#4.输出人脸数,dets的元素个数即为脸的个数
if len(rects) >= 1:
print("{} faces detected".format(len(rects)))
if len(rects) == 0:
raise NoFaces
for i in range(len(rects)):
#5.使用predictor进行人脸关键点识别
landmarks = numpy.matrix([[p.x,p.y] for p in predictor(im,rects[i]).parts()])
im = im.copy()
#使用enumerate 函数遍历序列中的元素以及它们的下标
for idx,point in enumerate(landmarks):
pos = (point[0,0],point[0,1])
cv2.putText(im,str(idx),pos,fontFace=cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
fontScale=0.4,color=(0,0,255))
#6.绘制特征点
cv2.circle(im,pos,3,color=(0,255,0))
cv2.namedWindow(“im”,2)
cv2.imshow(“im”,im)
cv2.waitKey(0)

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值