51、Window10+VS2019调用BAIDU的API进行活体检测

基本思想:给客户搞了个摄像头的人证比对历程,真艰辛;

本以为很简单的一个事情,最开始是人证比对,客户搞成了照片测试;我又搞成了眨眼测试,客户用上了手机播放视频;我又又搞成了手机检测,客户搞成了流媒体设备播放,深受其害,导入百度活体检测吧!

(1)、https://ai.baidu.com/ai-doc/FACE/4k37c1kj1 下载百度的C++ 活体检测SDK

51、Window10+VS2019调用BAIDU的API进行活体检测

 (2)、然后离线激活一下

51、Window10+VS2019调用BAIDU的API进行活体检测51、Window10+VS2019调用BAIDU的API进行活体检测

(3)将下载的License.zip 导入许可文件F:\temp\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk-demo\windows\face_demo\License.zip,然后测试

51、Window10+VS2019调用BAIDU的API进行活体检测

 (4)修改一下百度提供的vs工程,进行活体检测,效果还可以啊~ (测试官方提供的demo)

测试了一张图片,测试结果

rgb_img_path=G:\A.png
FaceSDK ---perf--- <line 32: bdface::bdface_create_img_instance> 0.739600ms
FaceSDK ---value--- <line 138: bdface::FaceBoxesDetect::_predict> output tensor size: 1
FaceSDK ---value--- <line 50: bdface::FaceDetectPreprocessor::run> detected faces size before filtered by score: 1
FaceSDK ---value--- <line 104: bdface::FaceDetectPreprocessor::run> detected faces size after filtered by score: 1
FaceSDK ---perf--- <line 180: bdface::bdface_detect> 16.067300ms
FaceSDK ---perf--- <line 143: bdface::bdface_align> 20.871900ms
FaceSDK ---perf--- <line 202: bdface::bdface_silent_live> 21.947800ms
face-demo ---info--- frame 1 -----------------------------------------------------
face-demo ---info--- rgb silent live test -- face 1:
face-demo ---info--- liveness value: 0.709688

(5)开始移植吧

添加头文件

D:\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk-demo\common\include
D:\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk\output\face_sdk\include
D:\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk-demo\third_party\zlib\windows\zlib\include
D:\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk-demo\third_party\libzip\include
D:\Opencv440\build\include\opencv2
D:\Opencv440\build\include

 添加库目录

D:\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk-demo\third_party\libzip\x64
D:\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk\output\face_sdk\x64
D:\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk-demo\third_party\zlib\windows\zlib\x64
D:\Opencv440\build\x64\vc15\lib

 添加lib库

face_sdk.lib
zip.lib

同时将官方提供的源码文件,拷贝到自己的工程中,先做一下删掉冗余文件吧~

51、Window10+VS2019调用BAIDU的API进行活体检测

 修改文件face_file_util.h,文件开头添加,同时拷贝新工程中

#pragma warning(disable:4996);

将opencv_world440.dll 、将D:\Baidu_Face_Offline_SDK_Windows_Cpp_V6.0\face-sdk-demo\windows\face_demo\x64\Release\*.dll都移动到可执行文件目录

将demo中模型拷贝到源码路径同时把官方的license.zip也拷贝到新工程中

align_rgb_float32_paddle.encrypted
detect_nir_int8_paddle.encrypted
silent_live_rgb_float32_paddle.encrypted
License.zip

修改新工程源码代码test_detect_rgb.h

 static StatusCode load_detect_ability(bdface::BDFaceInstance face_instance) {
        std::string detect_rgb_model_path = "F:\\sxj\\20210630\\ConsoleApplication2\\detect_nir_int8_paddle.encrypted";//添加绝对路径
        LOGI("loading rgb detect ability, model path: %s",
                detect_rgb_model_path.c_str());

修改新工程源码代码test_align_rgb_accurate.h

   static StatusCode load_align_ability(bdface::BDFaceInstance face_instance) {
        std::string align_rgb_accurate_model_path="F:\\sxj\\20210630\\ConsoleApplication2\\align_rgb_float32_paddle.encrypted";//添加绝对路径
        LOGI("loading accurate align rgb ability, model path: %s",
                align_rgb_accurate_model_path.c_str());

修改新工程源码代码test_silent_live_rgb.h

   static StatusCode load_silent_live_ability(bdface::BDFaceInstance face_instance) {
            std::string rgb_liveness_model_path = "F:\\sxj\\20210630\\ConsoleApplication2\\silent_live_rgb_float32_paddle.encrypted";//添加绝对路径
            LOGI("loading rgb live ability, model path: %s", rgb_liveness_model_path.c_str());

然后新工程测试活体检测demo就完成了,其它无用已经删掉

face-demo ---info--- loading rgb detect ability, model path: F:\sxj\20210630\ConsoleApplication2\detec
encrypted
face-demo ---info--- load detect rgb ability finished.

face-demo ---info--- loading accurate align rgb ability, model path: F:\sxj\20210630\ConsoleApplicatio
32_paddle.encrypted
Fused graph 0
face-demo ---info--- load accurate align rgb ability finished.

face-demo ---info--- loading rgb live ability, model path: F:\sxj\20210630\ConsoleApplication2\silent_
addle.encrypted
Fused graph 0
face-demo ---info--- load rgb live ability finished.

rgb_img_path=G:\q.jpg
face-demo ---info--- frame 1 -----------------------------------------------------
face-demo ---info--- rgb silent live test -- face 1:
face-demo ---info--- liveness value: 0.911451


F:\sxj\20210630\ConsoleApplication2\x64\Release\ConsoleApplication2.exe (进程 23568)已退出,代码为 0。

上一篇:鸿蒙HarmonyOS应用开发初体验


下一篇:强大的鸿蒙开发环境 —— DevEco Studio 2.1 Beta3发布