| | |
| | | package compare |
| | | |
| | | import ( |
| | | "encoding/base64" |
| | | "fmt" |
| | | "sdkCompare/util" |
| | | "strconv" |
| | | |
| | | "sdkCompare/cache" |
| | |
| | | if args.FaceFeature == nil { |
| | | return nil |
| | | } |
| | | |
| | | floatFeat := util.ByteSlice2float32Slice(args.FaceFeature) |
| | | |
| | | //指定最低分 |
| | | baseScore := thresholdLimit |
| | |
| | | if args.TreeNodes != nil && len(args.TreeNodes) > 0 { |
| | | for _, id := range args.TreeNodes { |
| | | if _, ok := cache.CacheMap.Area[id]; ok { |
| | | targets := cache.CacheMap.Area[id].Walk(DoSdkCompare, args.FaceFeature, baseScore) |
| | | targets := cache.CacheMap.Area[id].Walk(DoSdkCompare, floatFeat, baseScore) |
| | | if len(targets) > 0 { |
| | | scResult.CompareResult = append(scResult.CompareResult, targets...) |
| | | // 比对结果去重, 同一个人到访过多个小区, 缓存数据内会有多条记录 |
| | | for idx, t := range targets { |
| | | var isRepeat bool |
| | | for _, r := range scResult.CompareResult { |
| | | if t.Id == r.Id { |
| | | isRepeat = true |
| | | break |
| | | } |
| | | } |
| | | if !isRepeat { |
| | | scResult.CompareResult = append(scResult.CompareResult, targets[idx]) |
| | | } |
| | | } |
| | | } |
| | | |
| | | walkedArea[id] = struct{}{} |
| | |
| | | continue |
| | | } |
| | | |
| | | targets := val.Walk(DoSdkCompare, args.FaceFeature, baseScore) |
| | | targets := val.Walk(DoSdkCompare, floatFeat, baseScore) |
| | | if len(targets) > 0 { |
| | | scResult.CompareResult = append(scResult.CompareResult, targets...) |
| | | if len(targets) > 0 { |
| | | // 比对结果去重, 同一个人到访过多个小区, 缓存数据内会有多条记录 |
| | | for idx, t := range targets { |
| | | var isRepeat bool |
| | | for _, r := range scResult.CompareResult { |
| | | if t.Id == r.Id { |
| | | isRepeat = true |
| | | break |
| | | } |
| | | } |
| | | if !isRepeat { |
| | | scResult.CompareResult = append(scResult.CompareResult, targets[idx]) |
| | | } |
| | | } |
| | | } |
| | | // todo 添加小区外的关联关系, 下次优先比对 |
| | | } |
| | | } |
| | | |
| | | done: |
| | | logger.Debugf("比对结果 %d条", len(scResult.CompareResult)) |
| | | if len(scResult.CompareResult) > 0 { |
| | | logger.Debugf("比对结果%+v", scResult.CompareResult) |
| | | } |
| | | |
| | | buf, err := proto.Marshal(&scResult) |
| | | if err != nil { |
| | | logger.Error("scResult Marshal error!", err) |
| | |
| | | return buf |
| | | } |
| | | |
| | | func DoSdkCompare(ci []byte, co string) float32 { |
| | | co_d, err := base64.StdEncoding.DecodeString(co) |
| | | if err != nil { |
| | | logger.Error("DoSdkCompare err:", err) |
| | | return -1 |
| | | } |
| | | sec := DecCompare(ci, co_d) |
| | | func DoSdkCompare(ci, co []float32) float32 { |
| | | sec := DirectCompare(ci, co) |
| | | //logger.Debug("比对得分为:", sec) |
| | | |
| | | sec = ParseScore(sec) |