zoukankan      html  css  js  c++  java
  • 关于人脸检测python库 dlib 初识 1

    简介

    上了一门计算机视觉的课程,初步了解, dlib python库

    参考链接

    http://dlib.net/face_detector.py.html 人脸检测的链接

    原理

    This face detector is made using the now classic Histogram of Oriented
    Gradients (HOG) feature combined with a linear classifier, an image
    pyramid, and sliding window detection scheme. This type of object detector
    is fairly general and capable of detecting many types of semi-rigid objects
    in addition to human faces. Therefore, if you are interested in making
    your own object detectors then read the train_object_detector.py example program.

    谷歌翻译

    该面部检测器是使用现在经典的定向直方图(HOG)功能与线性分类器,图像金字塔和滑动窗口检测方案组合而成的。
    这种类型的物体检测器相当通用,并且能够检测除人脸之外的许多类型的半刚性物体。
    因此,如果您有兴趣制作自己的对象检测器,请阅读train_object_detector.py示例程序。
    如果没有猜错应该使用了传统的方法??

    想得到分数

    # Finally, if you really want to you can ask the detector to tell you the score
    # for each detection.  The score is bigger for more confident detections.
    # The third argument to run is an optional adjustment to the detection threshold,
    # where a negative value will return more detections and a positive value fewer.
    # Also, the idx tells you which of the face sub-detectors matched.  This can be
    # used to broadly identify faces in different orientations.
    

    code

    # coding=utf-8
    import dlib # 人脸算法库
    from imageio import imread
    import glob # 操作文件的相关模块
    
    # 准备好人脸检测器和显示窗口,获取图片路径
    detector = dlib.get_frontal_face_detector()
    win = dlib.image_window()
    paths=glob.glob('faces/*.jpg')
    # 对每一张图片进行检测,并显示检测结果对应的矩形框
    for path in paths:
        img = imread(path)
        # 1 表示将图片放大一杯,便于检测更过人脸
        dets = detector(img, 1)
        print('检测到了 %d 个人脸' % len(dets))
        for i,d in enumerate(dets): 
            # 函数用于将一个可遍历的数据对象(如列表、元组或字符串)
            # 组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。
            print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(i, d.left(), d.top(), d.right(), d.bottom())) # dets 是已经检测到的人脸
        win.clear_overlay() # 清除覆盖
        win.set_image(img)
        win.add_overlay(dets)
        dlib.hit_enter_to_continue()
        dets, scores, idx = detector.run(img, 1, -1) # 其中1 表示放大 -1 表示 阈值 如果为正数那么相关的低于阈值的信息就会被筛选掉
        for i, d in enumerate(dets):
            print("Detection {}, score: {}, face_type:{}".format(d, scores[i], idx[i]))
    

    结果

    检测到了 1 个人脸
    Detection 0: Left: 206 Top: 428 Right: 872 Bottom: 1094
    Hit enter to continue
    Detection [(206, 428) (872, 1094)], score: 2.9385107197297926, face_type:0
    Detection [(114, 744) (176, 806)], score: -0.7111557926037881, face_type:2
    Detection [(170, 847) (213, 890)], score: -0.8928528437771357, face_type:3
    Detection [(121, 793) (196, 868)], score: -0.9795470083884772, face_type:1

    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    usb驱动开发6之端点描述符
    usb驱动开发5之总线设备与接口
    usb驱动开发4之总线设备驱动模型
    usb驱动开发3之先看core
    usb驱动开发2之代码地图
    usb驱动开发1之学习准备
    javascript限制上传文件大小
    google Chrome打开多个网站时等待可用的套接字,怎么加大连接数量提升速度
    sql将一张表的字段赋值给另一张表
    百度搜索网址参数的含义
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13156212.html
Copyright © 2011-2022 走看看