68关键点----显示部分关键点

在这里插入图片描述

import os
import cv2
import dlib
import numpy as np
from imutils import face_utils

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("./pth/shape_predictor_68_face_landmarks.dat")

frame = cv2.imread('img.png')
cv2.imshow('frame', frame)
cv2.waitKey()

dets = detector(frame, 1)
for det in dets:
    # cv2.rectangle  参数1:图片, 参数2:左上角坐标, 参数2:左上角坐标, 参数3:右下角坐标, 参数4:颜色(R,G,B), 参数2:粗细
    # cv2.rectangle(frame_rec, (det.left(), det.top()), (det.right(), det.bottom()), (0, 255, 0), 2)  # 人脸识别框

    shape = predictor(frame, det)

    # for pt in shape.parts(): # 显示全部关键点
    #     pt_position = (pt.x,pt.y)
    #     cv2.circle(frame, pt_position, 1, (0, 0, 255), -1)  # 5:点的半径;-1:实心圆
	
	# shape = face_utils.shape_to_np(shape)
	# for (a, b) in shape:
	# cv2.circle(frame, (a, b), 1, (0, 0, 255), -1) #draw facial landmarks


    landmarks = np.matrix([[p.x, p.y] for p in shape.parts()])
    for idx, point in enumerate(landmarks):
        if idx in [17,21,22,26,30,48,54] :
            # 68点的坐标
            pos = (point[0, 0], point[0, 1])
            # 利用cv2.circle给每个特征点画一个圈,共68个
            cv2.circle(frame, pos, 2, color=(0, 0, 255))
            # 利用cv2.putText输出1-68
            font = cv2.FONT_HERSHEY_SIMPLEX
            cv2.putText(frame, str(idx + 1), pos, font, 0.5, (255, 0, 0), 1, cv2.LINE_AA)
            print("index=" + str(idx + 1) + " x=" + str(pos[0]) + " y=" + str(pos[1]))


cv2.imshow('frame', frame)
cv2.waitKey()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶叶梓梓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值