人脸关键点检测dlib python
·
脸特征点检测工具 dlib:
其中in Classes 表示采样(upsample)次数,返回值<class ‘dlib.dlib.rectangle’>,是一个矩形,坐标为[(x1, y1) (x2, y2)]。通过left,right,top,bottom方法分别获取对应的x1, x2, y1, y2值。
# dlib.get_frontal_face_datector(PythonFunction,in Classes) # python
import cv2
import dlib
img = cv2.imread('image.jpg')
detector = dlib.get_frontal_face_detetor()
dets = detector(gray_img, 1) # in Classes=1,in Classes 代表将原始图像是否进行放大,1表示放大1倍再检查,提高小人脸的检测效果
for i, d in enumerate(dets): # enumerate函数的返回值是迭代对象的索引和对应值 i:矩形索引 d:矩形坐标值
print(type(d))
y1 = d.top() if d.top() > 0 else 0 # d.area()函数计算面积的时候,数值是包含起始点的坐标的 d.area() = (x2 - x1 + 1)*(y2 - y1 + 1)
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
更多推荐



所有评论(0)