zhangzengfei
2022-01-10 4496b59ab27d569df1da7ef634e02273b3a9618a
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;
}