目录
1.结论
2.验证过程
2.1代码
2.2数据:传入图片(必应搜索获取)
2.3输出结果
3.参考致谢
1.结论
detector=dlib.get_frontal_face_detector() 获得脸部位置检测器
dets = detector(gray, 0) 返回值是<class 'dlib.dlib.rectangle'>,即一个矩形,表示为能够唯一表示这个人脸矩形框两个点坐标:左上角(x1,y1)、右下角(x2,y2)。
2.验证过程
2.1代码
import cv2
import dlib
img = cv2.imread(r'D:\i\1.jpg') #这里我用本地图片绝对路径
detector = dlib.get_frontal_face_detector()
#cv2.cvtColor(p1,p2) 是颜色空间转换函数,p1是需要转换的图片,p2是转换成何种格式
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)#将img转换为灰度图
dets = detector(gray, 0)
for i, d in enumerate(dets):
print(type(d))
y1 = d.top()
y2 = d.bottom()
x1 = d.left()
x2 = d.right()
print("i=" , i , "point of left_top (", x1 , ",", y1 ,") ",
" point of right_bottom (", x2 , ",", y2 ,")")
2.2数据:传入图片(必应搜索获取)
2.3输出结果
结果为图片的25张人脸
i : [ 0 , 24 ]
point of left_top为返回矩形 i 左上角顶点
point of right_bottom为返回矩形 i 右下角顶点
<class 'dlib.dlib.rectangle'>
i= 0 point of left_top ( 205 , 349 ) point of right_bottom ( 277 , 421 )
<class 'dlib.dlib.rectangle'>
i= 1 point of left_top ( 517 , 525 ) point of right_bottom ( 589 , 597 )
<class 'dlib.dlib.rectangle'>
i= 2 point of left_top ( 365 , 61 ) point of right_bottom ( 437 , 133 )
<class 'dlib.dlib.rectangle'>
i= 3 point of left_top ( 205 , 45 ) point of right_bottom ( 277 , 117 )
<class 'dlib.dlib.rectangle'>
i= 4 point of left_top ( 677 , 365 ) point of right_bottom ( 749 , 437 )
<class 'dlib.dlib.rectangle'>
i= 5 point of left_top ( 525 , 221 ) point of right_bottom ( 597 , 293 )
<class 'dlib.dlib.rectangle'>
i= 6 point of left_top ( 669 , 669 ) point of right_bottom ( 741 , 741 )
<class 'dlib.dlib.rectangle'>
i= 7 point of left_top ( 517 , 661 ) point of right_bottom ( 589 , 733 )
<class 'dlib.dlib.rectangle'>
i= 8 point of left_top ( 213 , 661 ) point of right_bottom ( 285 , 733 )
<class 'dlib.dlib.rectangle'>
i= 9 point of left_top ( 213 , 517 ) point of right_bottom ( 285 , 589 )
<class 'dlib.dlib.rectangle'>
i= 10 point of left_top ( 53 , 381 ) point of right_bottom ( 125 , 453 )
<class 'dlib.dlib.rectangle'>
i= 11 point of left_top ( 365 , 517 ) point of right_bottom ( 437 , 589 )
<class 'dlib.dlib.rectangle'>
i= 12 point of left_top ( 677 , 525 ) point of right_bottom ( 749 , 597 )
<class 'dlib.dlib.rectangle'>
i= 13 point of left_top ( 61 , 53 ) point of right_bottom ( 133 , 125 )
<class 'dlib.dlib.rectangle'>
i= 14 point of left_top ( 53 , 669 ) point of right_bottom ( 125 , 741 )
<class 'dlib.dlib.rectangle'>
i= 15 point of left_top ( 677 , 205 ) point of right_bottom ( 749 , 277 )
<class 'dlib.dlib.rectangle'>
i= 16 point of left_top ( 53 , 517 ) point of right_bottom ( 125 , 589 )
<class 'dlib.dlib.rectangle'>
i= 17 point of left_top ( 381 , 205 ) point of right_bottom ( 453 , 277 )
<class 'dlib.dlib.rectangle'>
i= 18 point of left_top ( 53 , 213 ) point of right_bottom ( 125 , 285 )
<class 'dlib.dlib.rectangle'>
i= 19 point of left_top ( 669 , 53 ) point of right_bottom ( 741 , 125 )
<class 'dlib.dlib.rectangle'>
i= 20 point of left_top ( 525 , 365 ) point of right_bottom ( 597 , 437 )
<class 'dlib.dlib.rectangle'>
i= 21 point of left_top ( 373 , 685 ) point of right_bottom ( 445 , 757 )
<class 'dlib.dlib.rectangle'>
i= 22 point of left_top ( 371 , 362 ) point of right_bottom ( 458 , 448 )
<class 'dlib.dlib.rectangle'>
i= 23 point of left_top ( 218 , 189 ) point of right_bottom ( 304 , 275 )
<class 'dlib.dlib.rectangle'>
i= 24 point of left_top ( 517 , 61 ) point of right_bottom ( 589 , 133 )
3.参考致谢
dlib.get_frontal_face_detector()函数返回值_南阜止鸟的博客-CSDN博客_dlib.get_frontal_face_detector detector = dlib.get_frontal_face_detector()获取人脸框的用法_夏华东的博客的博客-CSDN博客_dlib.get_frontal_face_detector文章来源:https://www.toymoban.com/news/detail-458819.html
小白学习ing...文章来源地址https://www.toymoban.com/news/detail-458819.html
到了这里,关于dlib.get_frontal_face_detector()及detector()返回值的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!