dlib.get_frontal_face_detector()函数

欢迎关注博主的公众号:happyGirl的异想世界。有更多干货还有技术讨论群哦~

dlib.get_frontal_face_datector(PythonFunction,in Classes)

其中in Classes 表示采样(upsample)次数

返回值是<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_detetor()
 
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:矩形坐标值

in Classes 暂时还没明白,但是找到的一些资料里都是写的1,如果哪位大牛知道是什么意思,还希望不吝赐教!

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

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

参考文献:

https://blog.csdn.net/weixin_41789707/article/details/79798224

 

  • 10
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值