From 7340eb0b160eacbbd0f3c2289e3ac6150da235f3 Mon Sep 17 00:00:00 2001
From: 554325746@qq.com <554325746@qq.com>
Date: 星期三, 25 十二月 2019 07:58:42 +0800
Subject: [PATCH] a

---
 app/src/main/cpp/native-lib.cpp |   75 +++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/app/src/main/cpp/native-lib.cpp b/app/src/main/cpp/native-lib.cpp
index 410b23a..68b6024 100644
--- a/app/src/main/cpp/native-lib.cpp
+++ b/app/src/main/cpp/native-lib.cpp
@@ -379,6 +379,8 @@
 unordered_map<string, shared_ptr<vector<unsigned char>>> featureMap;
 list<pair<string, shared_ptr<vector<unsigned char>>>> featureList;
 
+unordered_map<string, shared_ptr<vector<unsigned char>>> allFeatureMap;
+
 extern "C" JNIEXPORT void
 JNICALL
 Java_com_basic_security_utils_FaceId_addFeatureToDb(
@@ -417,6 +419,47 @@
         LogUtil::log(e.what());
     }
 }
+
+
+extern "C" JNIEXPORT void
+JNICALL
+Java_com_basic_security_utils_FaceId_addFeatureToAllDb(
+        JNIEnv *env, jobject, jstring id, jbyteArray featureBuffer) {
+    try {
+        if (featureBuffer == nullptr) {
+            return;
+        }
+        if (allFeatureMap.size() < 100 || 1 == 1) {
+            if (!useFeatureList) {
+                unsigned int max_size = allFeatureMap.max_size();
+                {
+                    int len = env->GetArrayLength(featureBuffer);
+                    shared_ptr<vector<unsigned char>> feature = make_shared<vector<unsigned char>>(len);
+                    env->GetByteArrayRegion(featureBuffer, 0, len,
+                                            reinterpret_cast<jbyte *>(feature.get()->data()));
+                    const char *sid = env->GetStringUTFChars(id, 0);
+                    allFeatureMap[sid] = feature;
+                }
+            }
+            /*if (useFeatureList) {
+                unsigned int max_size = allFeatureMap.max_size();
+                {
+                    int len = env->GetArrayLength(featureBuffer);
+                    shared_ptr<vector<unsigned char>> feature = make_shared<vector<unsigned char>>(len);
+                    env->GetByteArrayRegion(featureBuffer, 0, len,
+                                            reinterpret_cast<jbyte *>(feature.get()->data()));
+                    const char *sid = env->GetStringUTFChars(id, 0);
+                    featureListMutex.lock();
+                    featureList.push_back({sid, feature});
+                    featureListMutex.unlock();
+                }
+            }*/
+        }
+    } catch (exception &e) {
+        LogUtil::log(e.what());
+    }
+}
+
 
 unordered_map<string, shared_ptr<vector<unsigned char>>> tempFeatureMap;
 list<pair<string, shared_ptr<vector<unsigned char>>>> tempFeatureList;
@@ -541,6 +584,38 @@
 }
 
 
+
+extern "C" JNIEXPORT jstring
+JNICALL
+Java_com_basic_security_utils_FaceId_compareFeatureInAllDb(
+        JNIEnv *env, jobject, jbyteArray featureBuffer, jint minScore) {
+    float score = 0;
+    string result = ",0";
+    try {
+        env->GetByteArrayRegion(featureBuffer, 0, 2560, reinterpret_cast<jbyte *>(buf));
+        if (!useFeatureList) {
+            for (auto const &featureItem : allFeatureMap) {
+                string id = featureItem.first;
+                unsigned char *data = featureItem.second.get()->data();
+                printf("%s\n", id.c_str());
+                score = EF_Compare(buf, data)*100;
+                int i = 10;
+                if (score >= minScore) {
+                    result = "";
+                    result.append(id);
+                    result.append(",");
+                    result.append(to_string(score));
+                    break;
+                }
+            }
+        }
+    } catch (exception &e) {
+        LogUtil::log(e.what());
+    }
+    return env->NewStringUTF(result.c_str());
+}
+
+
 unsigned char tempFeatureBuf[2560];
 
 extern "C" JNIEXPORT jstring

--
Gitblit v1.8.0