From 88b1f1d1d14a8fe9e3dde2f363a89d821fc0e641 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 26 九月 2024 20:19:49 +0800 Subject: [PATCH] code format --- compare/faceSdk.go | 42 ++++++++++++++++++++++++++---------------- 1 files changed, 26 insertions(+), 16 deletions(-) diff --git a/compare/faceSdk.go b/compare/faceSdk.go index 6ffcf39..8ed054d 100644 --- a/compare/faceSdk.go +++ b/compare/faceSdk.go @@ -1,7 +1,7 @@ package compare import ( - "unsafe" + "sdkCompare/util" ) // #if FEATURE_NORMALIZE @@ -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 := util.ByteSlice2float32Slice(feat1) + ffeat2 := util.ByteSlice2float32Slice(feat2) + if len(feat1) != len(feat2) { return 0 } //fmt.Println("len:", len(ffeat1), len(feat2)) @@ -84,15 +105,4 @@ } //fmt.Println("score:", score) return score -} - -func byteSlice2float32Slice(src []byte) []float32 { - if len(src) == 0 { - return nil - } - - l := len(src) / 4 - ptr := unsafe.Pointer(&src[0]) - - return (*[1 << 26]float32)((*[1 << 26]float32)(ptr))[:l:l] } -- Gitblit v1.8.0