| | |
| | | |
| | | import ( |
| | | "fmt" |
| | | "sdkCompare/util" |
| | | "strconv" |
| | | |
| | | "sdkCompare/cache" |
| | | "sdkCompare/util" |
| | | |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/logger.git" |
| | |
| | | |
| | | const thresholdLimit = float32(30) |
| | | |
| | | func GetComparePersonBaseInfo(args protomsg.CompareArgs) []byte { |
| | | func Walk(args protomsg.CompareArgs) []byte { |
| | | if args.FaceFeature == nil { |
| | | return nil |
| | | } |
| | | |
| | | floatFeat := util.ByteSlice2float32Slice(args.FaceFeature) |
| | | fFeature := util.ByteSlice2float32Slice(args.FaceFeature) |
| | | |
| | | //指定最低分 |
| | | baseScore := thresholdLimit |
| | |
| | | } |
| | | |
| | | if args.IsCompareAll { |
| | | baseScore = 0 |
| | | baseScore = 25 |
| | | } |
| | | |
| | | var scResult protomsg.SdkCompareResult |
| | | logger.Debugf("Compare args treeNodes %+v, is all %v, target %s, feature len %d", args.TreeNodes, args.IsCompareAll, args.CompareTarget, len(fFeature)) |
| | | |
| | | var walkedArea = make(map[string]struct{}, 0) |
| | | // 优先比对传入的小区id |
| | | 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, floatFeat, baseScore) |
| | | if len(targets) > 0 { |
| | | scResult.CompareResult = append(scResult.CompareResult, targets...) |
| | | } |
| | | var response protomsg.SdkCompareResult |
| | | |
| | | walkedArea[id] = struct{}{} |
| | | } |
| | | } |
| | | |
| | | if len(scResult.CompareResult) > 0 { |
| | | goto done |
| | | } |
| | | // 抓拍库比对 |
| | | switch args.CompareTarget { |
| | | case "realName": |
| | | response = realNamePersonsCompere(args, fFeature, baseScore) |
| | | default: |
| | | response = capturePersonsCompere(args, fFeature, baseScore) |
| | | } |
| | | |
| | | // 比对以外的小区 |
| | | if !args.IsCompareAll && len(args.TreeNodes) > 0 { |
| | | baseScore += 20 |
| | | logger.Debugf("Compare target %s result len %d", args.CompareTarget, len(response.CompareResult)) |
| | | |
| | | if len(response.CompareResult) > 0 { |
| | | logger.Debugf("Compare result %+v", response.CompareResult) |
| | | } |
| | | |
| | | for key, val := range cache.CacheMap.Area { |
| | | if _, ok := walkedArea[key]; ok { |
| | | continue |
| | | } |
| | | |
| | | targets := val.Walk(DoSdkCompare, floatFeat, baseScore) |
| | | if len(targets) > 0 { |
| | | scResult.CompareResult = append(scResult.CompareResult, targets...) |
| | | // todo 添加小区外的关联关系, 下次优先比对 |
| | | } |
| | | } |
| | | |
| | | done: |
| | | logger.Debugf("比对结果 %d条", len(scResult.CompareResult)) |
| | | if len(scResult.CompareResult) > 0 { |
| | | logger.Debugf("比对结果%+v", scResult.CompareResult) |
| | | } |
| | | |
| | | buf, err := proto.Marshal(&scResult) |
| | | buf, err := proto.Marshal(&response) |
| | | if err != nil { |
| | | logger.Error("scResult Marshal error!", err) |
| | | logger.Error("response Marshal error!", err) |
| | | return nil |
| | | } |
| | | |