dlib.get_frontal_face_detector()及detector()返回值

目录

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

 小白学习ing...

  • 10
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
### 回答1: dlib.get_frontal_face_detector()是dlib用于检测人脸的函数。它可以用来检测图片或视频的人脸,返回人脸的位置和大小。这个函数使用的是深度学习技术,可以检测出图片的多个人脸。 ### 回答2: dlib.get_frontal_face_detector()是dlib的一个函数,功能是返回一个正脸检测器对象,可以用于检测图片或视频的正脸。在计算机视觉领域,正脸检测是一个基础任务,在很多应用场景都有广泛的应用,如人脸识别、表情识别、人脸口罩检测等。 这个函数返回的正脸检测器对象是基于HOG(Histogram of Oriented Gradients)算法的实现,HOG可以有效地提取图像的局部纹理、梯度等特征,通过训练分类器进行分类,从而实现目标检测。 使用dlib.get_frontal_face_detector()函数时,需要先加载dlib库,然后调用该函数即可得到正脸检测器对象。接下来,就可以对输入的图片或视频进行正脸检测了。 正脸检测器对象的使用方法是,调用detect()函数,传入要检测的图片或视频帧,即可返回一个矩形框列表,每个矩形框代表一张检测到的人脸区域。这些矩形框的位置、大小和姿态信息可以用来进一步进行人脸识别、表情识别等相关任务。 总之,dlib.get_frontal_face_detector()函数是dlib非常重要的一个函数,可以方便地实现基于HOG算法的正脸检测任务,为实现更多高级计算机视觉应用提供了基础支持。 ### 回答3: dlib.get_frontal_face_detector() 是 Dlib一个用于检测人脸的函数。Dlib 是一个 C++ 开发的开源计算机视觉库,广泛应用于图像处理及运算领域。 get_frontal_face_detector() 是 Dlib一个经典的人脸检测器,它基于 HOG 特征和线性分类器构建而成。该函数可对输入的图像进行前向人脸检测,返回检测到的人脸区域信息。此外,Dlib 还提供了其他许多人脸识别和检测的 API 接口,如人脸特征点检测、人脸识别等。 在使用 get_frontal_face_detector() 函数时,需要预先安装 Dlib 库并引入相关的头文件。函数的具体使用方法包括以下几步: 1. 创建一个 dlib::frontal_face_detector 对象,用于存储模型信息,例如: dlib::frontal_face_detector detector = dlib::get_frontal_face_detector(); 2. 加载待检测的图像,并将其转换为 dlib::array2d<dlib::rgb_pixel> 格式,例如: dlib::array2d<dlib::rgb_pixel> img; dlib::load_image(img, "test.jpg"); 3. 对图像进行前向人脸检测,并返回检测到人脸的矩形框信息,例如: std::vector<dlib::rectangle> faces = detector(img); 4. 可以将检测到的矩形框绘制到原图像上,以便查看检测效果,例如: for (size_t i = 0; i < faces.size(); ++i) dlib::draw_rectangle(img, faces[i], dlib::rgb_pixel(255,0,0), 3); 5. 最后可将检测结果输出到文件或显示出来,例如: dlib::save_jpeg(img, "output.jpg"); win.set_image(img); 总之,get_frontal_face_detector() 是 Dlib一个非常好用的人脸检测函数,能够轻松实现前向人脸检测,并可与其他 Dlib的函数一起使用,实现更加复杂的人脸应用。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值