dlib库的使用

**

一、dlib.get_frontal_face_detector()函数返回值

**

dlib.get_frontal_face_datector(PythonFunction,in Classes)

返回值是<class ‘dlib.dlib.rectangle’>,就是一个矩形

坐标为[(x1, y1) (x2, y2)]

可以通过函数的left,right,top,bottom方法分别获取对应的x1, x2, y1, y2值:

import cv2
import dlib
img = cv2.imread('my_image.jpg')
detector = dlib.get_frontal_face_detector()
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 
dets = detector(gray_img, 1)
for i, d in enumerate(dets):
            print(type(d))
            y1 = d.top() if d.top() > 0 else 0
            y2 = d.bottom() if d.bottom() > 0 else 0
            x1 = d.left() if d.left() > 0 else 0
            x2 = d.right() if d.right() > 0 else 0

enumerate函数的返回值是迭代对象的索引和对应值

i:矩形索引

d:矩形坐标值

最后打印一下就会得到相对应的值。这里要说明一下,当使用d.area()函数计算面积的时候,数值是包含起始点的坐标的:

x = x2 - x1 + 1
y = y2 - y1 + 1
d.area() = x * y

**

二、predictor = dlib.shape_predictor()关键点预测器用法

**
predictor = dlib.shape_predictor(‘data/data_dlib/shape_predictor_68_face_landmarks.dat’)
功能:标记人脸关键点
参数:‘data/data_dlib/shape_predictor_68_face_landmarks.dat’:68个关键点模型地址
返回值:人脸关键点预测器

shape = predictor(img, box)
功能:定位人脸关键点
参数:img:一个numpy ndarray,包含8位灰度或RGB图像
   box:开始内部形状预测的边界框
返回值:68个关键点的位置

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Cynthia.Chen

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

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

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

打赏作者

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

抵扣说明:

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

余额充值