dlib 03 dlib自带demo 人脸关键点检测器训练和测试

01 dlib自带demo

dlib库自带了比较完整的c++版本demo和python版本demo。
C++版本demo在 dlib/examples目录。
Python版本demo在dlib/python_examples。
demo的部分资源在:
dlib/examples/faces
dlib/examples/johns
dlib/examples/video_frames
demo另外需要的资源,在对应demo代码注释中可以找到。主要是一些训练好的模型。

02 人脸关键点检测器训练

02.01 人脸关键点检测器训练 资源

dlib提供了68个关键点的人脸图片及对应的数据文件。
代码:dlib\examples\train_shape_predictor_ex.cpp
工程名:train_shape_predictor_ex
测试数据:dlib\examples\faces
训练数据集图片
dlib\examples\faces\training_with_face_landmarks.xml
dlib\examples\faces\2007_007763.jpg
dlib\examples\faces\2008_001009.jpg
dlib\examples\faces\2008_001322.jpg
dlib\examples\faces\2008_002079.jpg
测试数据及图片
dlib\examples\faces\testing_with_face_landmarks.xml
dlib\examples\faces\2008_002470.jpg
dlib\examples\faces\2008_002506.jpg
dlib\examples\faces\2008_004176.jpg
dlib\examples\faces\2008_007676.jpg
dlib\examples\faces\2009_004587.jpg

dlib 03 dlib自带demo 人脸关键点检测器训练和测试_第1张图片

02.02 项目设置

把examples解决方案中的train_shape_predictor_ex工程设置为启动项。

配置属性==>调试==>命令参数==>..\..\..\examples\faces
配置属性==>调试==>工作目录==>$(OutDir)

dlib 03 dlib自带demo 人脸关键点检测器训练和测试_第2张图片

02.03 训练

Debug版本训练大约33分钟,Release版本训练大约1.8分钟。
dlib 03 dlib自带demo 人脸关键点检测器训练和测试_第3张图片

dlib 03 dlib自带demo 人脸关键点检测器训练和测试_第4张图片

训练结果:

Fitting trees...
Training complete
mean training error: 2.40105e-05
mean testing error:  0.0867148

生成15.8MB的 dlib\build\x64_19.6_examples\Debug\sp.dat模型文件。
dlib 03 dlib自带demo 人脸关键点检测器训练和测试_第5张图片

02.04 测试

使用人脸关键点检测demo,face_landmark_detection_ex。参见03

03 人脸关键点检测

02.01 人脸关键点检测 资源

dlib提供了68个关键点的人脸图片及对应的数据文件。
代码:dlib\examples\face_landmark_detection_ex.cpp
工程名:face_landmark_detection_ex
测试数据:dlib\examples\faces
dlib\examples\faces\bald_guys.jpg # 有人脸
dlib\examples\faces\dogs.jpg # 没人脸
也可以是其他任何人脸图片

02 中生成的sp.dat模型文件。

03.02 项目配置

把examples解决方案中的train_shape_predictor_ex工程设置为启动项。

配置属性==>调试==>命令参数==>sp.dat ..\..\..\examples\faces\bald_guys.jpg
配置属性==>调试==>工作目录==>$(OutDir)

dlib 03 dlib自带demo 人脸关键点检测器训练和测试_第6张图片

03.03 运行效果

测试01:sp.dat ……\examples\faces\bald_guys.jpg

processing image ..\..\..\examples\faces\bald_guys.jpg
Number of faces detected: 24
number of parts: 68
pixel position of first part:  (2939, 2768)
pixel position of second part: (2935, 2796)
number of parts: 68
pixel position of first part:  (2149, 2707)
pixel position of second part: (2148, 2759)
number of parts: 68
pixel position of first part:  (130, 247)
pixel position of second part: (128, 292)
number of parts: 68
pixel position of first part:  (2111, 1626)
pixel position of second part: (2110, 1676)
number of parts: 68
pixel position of first part:  (1132, 1004)
pixel position of second part: (1139, 1047)
number of parts: 68
pixel position of first part:  (3657, 954)
pixel position of second part: (3659, 984)
number of parts: 68
pixel position of first part:  (125, 2724)
pixel position of second part: (118, 2760)
number of parts: 68
pixel position of first part:  (1576, 1755)
pixel position of second part: (1580, 1793)
number of parts: 68
pixel position of first part:  (152, 1491)
pixel position of second part: (150, 1529)
number of parts: 68
pixel position of first part:  (120, 873)
pixel position of second part: (127, 918)
number of parts: 68
pixel position of first part:  (662, 982)
pixel position of second part: (663, 1022)
number of parts: 68
pixel position of first part:  (3309, 1453)
pixel position of second part: (3308, 1478)
number of parts: 68
pixel position of first part:  (723, 2587)
pixel position of second part: (723, 2636)
number of parts: 68
pixel position of first part:  (1755, 914)
pixel position of second part: (1761, 959)
number of parts: 68
pixel position of first part:  (119, 2073)
pixel position of second part: (119, 2111)
number of parts: 68
pixel position of first part:  (768, 1735)
pixel position of second part: (767, 1799)
number of parts: 68
pixel position of first part:  (719, 173)
pixel position of second part: (715, 196)
number of parts: 68
pixel position of first part:  (1561, 2588)
pixel position of second part: (1563, 2631)
number of parts: 68
pixel position of first part:  (1136, 348)
pixel position of second part: (1135, 381)
number of parts: 68
pixel position of first part:  (2221, 2237)
pixel position of second part: (2221, 2279)
number of parts: 68
pixel position of first part:  (654, 542)
pixel position of second part: (649, 568)
number of parts: 68
pixel position of first part:  (3548, 2661)
pixel position of second part: (3554, 2719)
number of parts: 68
pixel position of first part:  (2830, 340)
pixel position of second part: (2819, 436)
number of parts: 68
pixel position of first part:  (1729, 287)
pixel position of second part: (1724, 333)
Hit enter to process the next image...

dlib 03 dlib自带demo 人脸关键点检测器训练和测试_第7张图片

测试02:

processing image ..\..\..\examples\faces\dogs.jpg
Number of faces detected: 0
Hit enter to process the next image...

dlib 03 dlib自带demo 人脸关键点检测器训练和测试_第8张图片

你可能感兴趣的:(dlib,dlib)