天天看點

Py之dlib:Python庫之dlib庫的簡介、安裝、使用方法詳細攻略(二)

dlib庫的使用函數

0、利用dlib.get_frontal_face_detector函數實作人臉檢測可視化

CV之dlib:利用dlib.get_frontal_face_detector函數實作人臉檢測

Py之dlib:Python庫之dlib庫的簡介、安裝、使用方法詳細攻略(二)
Py之dlib:Python庫之dlib庫的簡介、安裝、使用方法詳細攻略(二)

1、hog提取特征的函數

dlib.get_frontal_face_detector()    #人臉特征提取器,該函數是在C++裡面定義的

help(dlib.get_frontal_face_detector())

Help on fhog_object_detector in module dlib.dlib object:

class fhog_object_detector(Boost.Python.instance)

|  This object represents a sliding window histogram-of-oriented-gradients based object detector.

|

|  Method resolution order:

|      fhog_object_detector

|      Boost.Python.instance

|      builtins.object

|  Methods defined here:

|  __call__(...)

|      __call__( (fhog_object_detector)arg1, (object)image [, (int)upsample_num_times=0]) -> rectangles :

|          requires

|              - image is a numpy ndarray containing either an 8bit grayscale or RGB

|                image.

|              - upsample_num_times >= 0

|          ensures

|              - This function runs the object detector on the input image and returns

|                a list of detections.

|              - Upsamples the image upsample_num_times before running the basic

|                detector.

|  __getstate__(...)

|      __getstate__( (fhog_object_detector)arg1) -> tuple

|  __init__(...)

|      __init__( (object)arg1) -> None

|      __init__( (object)arg1, (str)arg2) -> object :

|          Loads an object detector from a file that contains the output of the

|          train_simple_object_detector() routine or a serialized C++ object of type

|          object_detector<scan_fhog_pyramid<pyramid_down<6>>>.

|  __reduce__ = <unnamed Boost.Python function>(...)

|  __setstate__(...)

|      __setstate__( (fhog_object_detector)arg1, (tuple)arg2) -> None

|  run(...)

|      run( (fhog_object_detector)arg1, (object)image [, (int)upsample_num_times=0 [, (float)adjust_threshold=0.0]]) -> tuple :

|                a tuple of (list of detections, list of scores, list of weight_indices).

|  save(...)

|      save( (fhog_object_detector)arg1, (str)detector_output_filename) -> None :

|          Save a simple_object_detector to the provided path.

|  ----------------------------------------------------------------------

|  Static methods defined here:

|  run_multiple(...)

|      run_multiple( (list)detectors, (object)image [, (int)upsample_num_times=0 [, (float)adjust_threshold=0.0]]) -> tuple :

|              - detectors is a list of detectors.

|              - This function runs the list of object detectors at once on the input image and returns

|  Data and other attributes defined here:

|  __instance_size__ = 160

|  __safe_for_unpickling__ = True

|  Methods inherited from Boost.Python.instance:

|  __new__(*args, **kwargs) from Boost.Python.class

|      Create and return a new object.  See help(type) for accurate signature.

|  Data descriptors inherited from Boost.Python.instance:

|  __dict__

|  __weakref__

2、CNN提取特征的函數

cnn_face_detector = dlib.cnn_face_detection_model_v1(cnn_face_detection_model)

help(dlib.cnn_face_detection_model_v1)

Help on class cnn_face_detection_model_v1 in module dlib.dlib:

class cnn_face_detection_model_v1(Boost.Python.instance)

|  This object detects human faces in an image.  The constructor loads the face detection model from a file. You can download a pre-trained model from

http://dlib.net/files/mmod_human_face_detector.dat.bz2.

|

|      cnn_face_detection_model_v1

|      __call__( (cnn_face_detection_model_v1)arg1, (object)img [, (int)upsample_num_times=0]) -> mmod_rectangles :

|          Find faces in an image using a deep learning model.

|                    - Upsamples the image upsample_num_times before running the face

|                      detector.

|      __call__( (cnn_face_detection_model_v1)arg1, (list)imgs [, (int)upsample_num_times=0 [, (int)batch_size=128]]) -> mmod_rectangless :

|          takes a list of images as input returning a 2d list of mmod rectangles

|      __init__( (object)arg1, (str)arg2) -> None

|  __instance_size__ = 984

inline frontal_face_detector get_frontal_face_detector()