From 3c5bc166a563cd851f3e3b5e1a019f7fa0207ab0 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 18 四月 2024 23:22:01 +0800 Subject: [PATCH] fix cycle import --- compare/compare.go | 3 ++- compare/faceSdk.go | 17 +++-------------- db/person.go | 6 +++--- util/util.go | 12 ++++++++++++ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/compare/compare.go b/compare/compare.go index 2fc28b5..ed5bfeb 100644 --- a/compare/compare.go +++ b/compare/compare.go @@ -2,6 +2,7 @@ import ( "fmt" + "sdkCompare/util" "strconv" "sdkCompare/cache" @@ -18,7 +19,7 @@ return nil } - floatFeat := ByteSlice2float32Slice(args.FaceFeature) + floatFeat := util.ByteSlice2float32Slice(args.FaceFeature) //鎸囧畾鏈�浣庡垎 baseScore := thresholdLimit diff --git a/compare/faceSdk.go b/compare/faceSdk.go index 49fa258..8ed054d 100644 --- a/compare/faceSdk.go +++ b/compare/faceSdk.go @@ -1,7 +1,7 @@ package compare import ( - "unsafe" + "sdkCompare/util" ) // #if FEATURE_NORMALIZE @@ -84,8 +84,8 @@ } func DecCompare(feat1, feat2 []byte) float32 { - ffeat1 := ByteSlice2float32Slice(feat1) - ffeat2 := ByteSlice2float32Slice(feat2) + ffeat1 := util.ByteSlice2float32Slice(feat1) + ffeat2 := util.ByteSlice2float32Slice(feat2) if len(feat1) != len(feat2) { return 0 } @@ -105,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] } diff --git a/db/person.go b/db/person.go index 3224daa..7bdd7ca 100644 --- a/db/person.go +++ b/db/person.go @@ -2,7 +2,7 @@ import ( "encoding/base64" - "sdkCompare/compare" + "sdkCompare/util" "strconv" ) @@ -66,7 +66,7 @@ Id: p.Id, TableId: p.TableId, AreaId: p.AreaID, - FaceFeature: compare.ByteSlice2float32Slice(byteFeat), + FaceFeature: util.ByteSlice2float32Slice(byteFeat), Enable: int32(p.Enable), }) } @@ -91,7 +91,7 @@ Id: p.Id, TableId: p.TableId, AreaId: p.AreaID, - FaceFeature: compare.ByteSlice2float32Slice(byteFeat), + FaceFeature: util.ByteSlice2float32Slice(byteFeat), Enable: int32(p.Enable), } } diff --git a/util/util.go b/util/util.go index 30914cc..a7efd35 100644 --- a/util/util.go +++ b/util/util.go @@ -5,6 +5,7 @@ "errors" "net" "strconv" + "unsafe" ) // 鑾峰彇鏈満缃戝崱IP @@ -70,3 +71,14 @@ } return c == len(arr) } + +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