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

training_with_face_landmarks.xml

02.02 项目设置

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

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

这里写图片描述

02.03 训练

Debug版本训练大约33分钟,Release版本训练大约1.8分钟。
Debug

Release

训练结果:

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模型文件。
sp.dat

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)

这里写图片描述

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...

人脸检测测试效果图

测试02:

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

狗脸图片未检测到人脸

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值