dlib.get_frontal_face_detector()函数返回值

IT小白的第一篇博客

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
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:矩形坐标值

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

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

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

扫描二维码关注公众号,回复: 1727050 查看本文章


猜你喜欢

转载自blog.csdn.net/weixin_41789707/article/details/79798224
今日推荐