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 # $
    python英文学习字典
    python中read(),readline(),和readlines()
    if _name_ =="_main_"
    win10菜单打不开,任务栏右击没有反应
    python中csv转json文件出现:File was loaded in the wrong encoding: 'UTF-8'
    Python字典
    python 匿名函数实现求素数平方和
    Python快速排序的实现
    P1880 [NOI1995]石子合并
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13156449.html
Copyright © 2011-2022 走看看