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

    简介

    关于人脸检测算法python库的初步认识2

    使用CNN的实现人脸检测

    简单说明

    The example loads a pretrained model and uses it to find faces in images. 这个是使用已经训练好的模型
    CNN model is much more accurate than the HOG based model shown in the face_detector.py CNN训练的模型相对于HOG有更好的精准性。 放在GPU上才能达到更好的速度。

    code

    #!/usr/bin/python
    # The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
    #
    #   This example shows how to run a CNN based face detector using dlib.  The
    #   example loads a pretrained model and uses it to find faces in images.  The
    #   CNN model is much more accurate than the HOG based model shown in the
    #   face_detector.py example, but takes much more computational power to
    #   run, and is meant to be executed on a GPU to attain reasonable speed.
    #
    #   You can download the pre-trained model from:
    #       http://dlib.net/files/mmod_human_face_detector.dat.bz2
    #
    #   The examples/faces folder contains some jpg images of people.  You can run
    #   this program on them and see the detections by executing the
    #   following command:
    #       ./cnn_face_detector.py mmod_human_face_detector.dat ../examples/faces/*.jpg
    #
    #
    # COMPILING/INSTALLING THE DLIB PYTHON INTERFACE
    #   You can install dlib using the command:
    #       pip install dlib
    #
    #   Alternatively, if you want to compile dlib yourself then go into the dlib
    #   root folder and run:
    #       python setup.py install
    #
    #   Compiling dlib should work on any operating system so long as you have
    #   CMake installed.  On Ubuntu, this can be done easily by running the
    #   command:
    #       sudo apt-get install cmake
    #
    #   Also note that this example requires Numpy which can be installed
    #   via the command:
    #       pip install numpy
    
    import glob
    from imageio import imread
    import dlib
    
    paths=glob.glob('faces/*.jpg')
    cnn_face_detector = dlib.cnn_face_detection_model_v1('mmod_human_face_detector.dat')
    win = dlib.image_window()
    for path in paths:
        img = imread(path)
        dets = cnn_face_detector(img, 1)
        for i,d in enumerate(dets):
            print("Detection {}: Left: {} Top: {} Right: {} Bottom: {} Confidence: {}".format(
                i, d.rect.left(), d.rect.top(), d.rect.right(), d.rect.bottom(), d.confidence))
            rects = dlib.rectangles()
            rects.extend([d.rect for d in dets])
            win.clear_overlay()
            win.set_image(img)
            win.add_overlay(rects)
            dlib.hit_enter_to_continue()
    

    训练好的CNN模型

    mmod_human_face_detector.dat
    下载地址 http://dlib.net/files/mmod_human_face_detector.dat.bz2

    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    Linux下CPU利用率和负载的关系
    Linux系统中的load average(平均负载/运行队列)
    性能测试分析及调优准备
    解读Loadrunner网页细分图(Web Page Diagnostics)
    LR性能测试分析流程
    【转】多数据源
    【转】BAT启动执行JAVA JAR文件中的MAIN方法的两种方式
    【转】java.net.SocketException
    [webservices]怎样用SoapUI测试接口
    【转】了解webservice
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13156449.html
Copyright © 2011-2022 走看看