From bdcc9624341ee34298be74a706b09f12f8306456 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期四, 18 四月 2024 23:16:56 +0800
Subject: [PATCH] 优化缓存的数据, 取消多次的base64计算和float32转换

---
 compare/faceSdk.go |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/compare/faceSdk.go b/compare/faceSdk.go
index 6ffcf39..49fa258 100644
--- a/compare/faceSdk.go
+++ b/compare/faceSdk.go
@@ -62,10 +62,31 @@
 
 //	    return  fscore;
 //	}
-func DecCompare(feat1 []byte, feat2 []byte) float32 {
-	ffeat1 := byteSlice2float32Slice(feat1)
-	ffeat2 := byteSlice2float32Slice(feat2)
-	if len(ffeat1) != len(ffeat2) {
+func DirectCompare(feat1 []float32, feat2 []float32) float32 {
+	if len(feat1) != len(feat2) {
+		return 0
+	}
+
+	var score float32
+	for i := 0; i < 1536; i++ {
+		score += feat1[i] * feat2[i]
+	}
+	score += 0.05
+	if score > 0.9999 {
+		score = 0.9999
+	}
+	if score < 0.0001 {
+		score = 0.0001
+	}
+
+	//fmt.Println("score:", score)
+	return score
+}
+
+func DecCompare(feat1, feat2 []byte) float32 {
+	ffeat1 := ByteSlice2float32Slice(feat1)
+	ffeat2 := ByteSlice2float32Slice(feat2)
+	if len(feat1) != len(feat2) {
 		return 0
 	}
 	//fmt.Println("len:", len(ffeat1), len(feat2))
@@ -86,7 +107,7 @@
 	return score
 }
 
-func byteSlice2float32Slice(src []byte) []float32 {
+func ByteSlice2float32Slice(src []byte) []float32 {
 	if len(src) == 0 {
 		return nil
 	}

--
Gitblit v1.8.0