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

一個處女座的程式猿發表於2018-03-24

 

dlib庫的簡介

    一個機器學習的開源庫,包含了機器學習的很多演算法,使用起來很方便,直接包含標頭檔案即可,並且不依賴於其他庫(自帶影象編解碼庫原始碼)。Dlib可以幫助您建立很多複雜的機器學習方面的軟體來幫助解決實際問題。目前Dlib已經被廣泛的用在行業和學術領域,包括機器人,嵌入式裝置,行動電話和大型高效能運算環境。

Dlib是一個使用現代C++技術編寫的跨平臺的通用庫,遵守Boost Software licence. 主要特點如下: 
1.完善的文件:每個類每個函式都有詳細的文件,並且提供了大量的示例程式碼,如果你發現文件描述不清晰或者沒有文件,告訴作者,作者會立刻新增。 
2.可移植程式碼:程式碼符合ISO C++標準,不需要第三方庫支援,支援win32、Linux、Mac OS X、Solaris、HPUX、BSDs 和 POSIX 系統 
3.執行緒支援:提供簡單的可移植的執行緒API 
4.網路支援:提供簡單的可移植的Socket API和一個簡單的Http伺服器 
5.圖形使用者介面:提供執行緒安全的GUI API 
6.數值演算法:矩陣、大整數、隨機數運算等 
7.機器學習演算法:
8.圖形模型演算法: 
9.影象處理:支援讀寫Windows BMP檔案,不同型別色彩轉換 
10.資料壓縮和完整性演算法:CRC32、Md5、不同形式的PPM演算法 
11.測試:執行緒安全的日誌類和模組化的單元測試框架以及各種測試assert支援
12.一般工具:XML解析、記憶體管理、型別安全的big/little endian轉換、序列化支援和容器類


dlib pypi
dlib庫
dlib c++ library

 

 

dlib庫的安裝

本部落格提供三種方法進行安裝

T1方法:pip install dlib

此方法是需要在你安裝cmake、Boost環境的計算機使用

T2方法:conda install -c menpo dlib=18.18

此方法適合那些已經安裝好conda庫的環境的計算機使用,conda庫的安裝本部落格有詳細攻略,請自行翻看。

T3方法:pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl

dlib庫的whl檔案——dlib-19.7.0-cp36-cp36m-win_amd64.rar

dlib-19.3.1-cp35-cp35m-win_amd64.whl

哈哈,大功告成!如有資料或問題需求,請留言!

 

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 :
 |          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 tuple of (list of detections, list of scores, list of weight_indices).
 |              - Upsamples the image upsample_num_times before running the basic
 |                detector.
 |
 |  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 :
 |          requires
 |              - detectors is a list of detectors.
 |              - image is a numpy ndarray containing either an 8bit grayscale or RGB
 |                image.
 |              - upsample_num_times >= 0
 |          ensures
 |              - This function runs the list of object detectors at once on the input image and returns
 |                a tuple of (list of detections, list of scores, list of weight_indices).
 |              - Upsamples the image upsample_num_times before running the basic
 |                detector.
 |
 |  ----------------------------------------------------------------------
 |  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.
 |
 |  Method resolution order:
 |      cnn_face_detection_model_v1
 |      Boost.Python.instance
 |      builtins.object
 |
 |  Methods defined here:
 |
 |  __call__(...)
 |      __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__(...)
 |      __init__( (object)arg1, (str)arg2) -> None
 |
 |  __reduce__ = <unnamed Boost.Python function>(...)
 |
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |
 |  __instance_size__ = 984
 |
 |  ----------------------------------------------------------------------
 |  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__

 

inline frontal_face_detector get_frontal_face_detector()
 


 

相關文章