package face
|
|
import (
|
"unsafe"
|
)
|
|
func DecCompare(feat1 []byte, feat2 []byte) float32 {
|
ffeat1 := byteSlice2float32Slice(feat1)
|
ffeat2 := byteSlice2float32Slice(feat2)
|
if len(ffeat1) != len(ffeat2) {
|
return 0
|
}
|
// normalize
|
var score float32
|
for i := 0; i < len(ffeat1); i++ {
|
score += ffeat1[i] * ffeat2[i]
|
}
|
score += 0.05
|
if score > 0.9999 {
|
score = 0.9999
|
}
|
if score < 0.0001 {
|
score = 0.0001
|
}
|
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)(ptr)[:l:l]
|
}
|