From 4496b59ab27d569df1da7ef634e02273b3a9618a Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期一, 10 一月 2022 17:15:09 +0800 Subject: [PATCH] 更新人脸算法 --- app/src/main/cpp/FaceDetectHelper.cpp | 78 ++++++++++++++++++++++++++++---------- 1 files changed, 57 insertions(+), 21 deletions(-) diff --git a/app/src/main/cpp/FaceDetectHelper.cpp b/app/src/main/cpp/FaceDetectHelper.cpp index f5b06f2..40a08cb 100644 --- a/app/src/main/cpp/FaceDetectHelper.cpp +++ b/app/src/main/cpp/FaceDetectHelper.cpp @@ -15,6 +15,7 @@ #include <json/json.h> #include <memory> #include "THFeature_i.h" +#include "TH_AES.h" #include "FaceDetectHelper.h" #include "LogUtil.h" #include <memory> @@ -67,45 +68,80 @@ BYTE* feature1 = nullptr; BYTE* idcard_feature = nullptr; int featureSize = 0; -bool FaceDetectHelper::initSdk(const char* modelPath) { +bool FaceDetectHelper::initSdk(const char *modelPath) { +// LOGI("initSdk....\n"); if (!init_sdk_success) { + int nOK = -1; + //AES check for THFaceImage + BYTE pRequest[16]; + nOK = THFI_DetectFace(-101, pRequest, 0, 0, 0, 0, 0, 0); + if (nOK == 0) { + printf("THFaceImage->Request random number success.\n"); + } else { + printf("THFaceImage->Request random number failed.\n"); + return -1; + } + + BYTE *pRand = pRequest; + TH_SDK_Encrypt(pRand); + nOK = THFI_DetectFace(-102, pRand, 0, 0, 0, 0, 0, 0); + if (nOK == 0) { + printf("THFaceImage->AES check success.\n"); + } else { + printf("THFaceImage->AES check failed.\n"); + return -1; + } + + //AES check for THFeature + nOK = EF_Extract(-101, pRequest, 0, 0, 0, 0, 0); + if (nOK == 0) { + printf("THFeature->Request random number success.\n"); + } else { + printf("THFeature->Request random number failed.\n"); + return -1; + } + + pRand = pRequest; + TH_SDK_Encrypt(pRand); + nOK = EF_Extract(-102, pRand, 0, 0, 0, 0, 0); + if (nOK == 0) { + printf("THFeature->AES check success.\n"); + } else { + printf("THFeature->AES check failed.\n"); + return -1; + } + + //CPU妯″紡:0-澶у皬鏍革紝1-浠呭皬鏍革紝2-浠呭ぇ鏍� + int cpu_mode = 0; + //鍚敤gpu璁$畻:0-涓嶅惎鐢紝1-鍚敤 + int nGpu = 0; + //骞惰璁$畻绾跨▼鏁� int nOmpThreadNum = 2; - THFI_Param detParam; - detParam.nMinFaceSize = 50; - detParam.nRollAngle = 30; - detParam.bOnlyDetect = false; - detParam.dwReserved = NULL; + int nChannel_Num = 1; + THFI_SetDir(modelPath, modelPath); -// int ret = THFI_Create(1, &detParam); +// int ret = THFI_Create_Allin(nChannel_Num, cpu_mode, nOmpThreadNum, nGpu); int ret = THFI_Create_Ex(2, nOmpThreadNum); - if (ret < 0) { - printf("THFI_Create failed!(ret=%d)\n", ret); + if (ret < 1) { init_sdk_success = false; return init_sdk_success; } -// THFL_SDK_SetDir(modelPath, modelPath); -// ret = THFL_Create(1); -// if (ret < 0) { -// printf("THFL_Create failed!(ret=%d)\n", ret); -// THFI_Release(); -// init_sdk_success = false; -// return init_sdk_success; -// } + EF_SetDir(modelPath, modelPath); -// ret=EF_Init(1); +// ret = EF_Init_Allin(nChannel_Num, cpu_mode, nOmpThreadNum, nGpu); ret=EF_Init_Ex(2, nOmpThreadNum); - if (ret < 0) - { - printf("EF_Init failed!(ret=%d)\n",ret); + if (ret < 1) { THFI_Release(); init_sdk_success = false; return init_sdk_success; } + featureSize = EF_Size(); feature1 = new BYTE[featureSize]; idcard_feature = new BYTE[featureSize]; init_sdk_success = true; } + return init_sdk_success; } -- Gitblit v1.8.0