| | |
| | | "nanomsg.org/go-mangos/transport/tcp" |
| | | "net" |
| | | "ruleprocess/cache" |
| | | "ruleprocess/logger" |
| | | "basic.com/valib/logger.git" |
| | | "ruleprocess/structure" |
| | | "strconv" |
| | | "time" |
| | | ) |
| | |
| | | } |
| | | |
| | | // 给目标填充liker |
| | | func (arg *Arg) fillLiker(tableId []string, compareThreshold float32) { |
| | | func fillLiker(tableId []string, compareThreshold float32,arg *structure.Arg) { |
| | | //bytes := bigCache.GetComparePersonBaseInfo(tableId, arg.Feature, compareThreshold) |
| | | comArg := &protomsg.CompareArgs{ |
| | | TableIds:tableId, |
| | |
| | | logger.Error("根据id查询底库信息出错!", err, "--返回值长度为:", len(table)) |
| | | } |
| | | logger.Debug("看看这个base的对比值是多少:", Decimal(m[baseinfo.Id].CompareScore)) |
| | | base := BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id].CompareScore), PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved} |
| | | base := structure.BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id].CompareScore), PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved} |
| | | //os.Exit(1) |
| | | arg.Liker = append(arg.Liker, &base) |
| | | } |
| | |
| | | } |
| | | |
| | | // 人脸比对 |
| | | func Compare(args *SdkDatas, groupRule *protomsg.GroupRule) { |
| | | func Compare(args *structure.SdkDatas, groupRule *protomsg.GroupRule) { |
| | | compareFlag := 0 |
| | | var tableIds []string |
| | | var threshold float32 = 50 // 默认阈值为50 |
| | |
| | | if groupRule.Rules[j].SdkArgAlias == "compareBase" && groupRule.Rules[j].SdkArgValue == "" { // 配的参数是比对全部底库 |
| | | compareFlag = 1 |
| | | } |
| | | if groupRule.Rules[j].SdkArgAlias == "threshold" { |
| | | if groupRule.Rules[j].SdkArgAlias == "cmpThreshold" { |
| | | v2, err := strconv.ParseFloat(groupRule.Rules[j].SdkArgValue, 32) |
| | | if err != nil { |
| | | logger.Error("string转float32失败!") |
| | |
| | | logger.Info("============================================进行人脸对比") |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | // 拿区域中每个人脸特征值去对比,填充其liker |
| | | if groupRule.Rules[j].PolygonId == areaMap.areaId { |
| | | if groupRule.Rules[j].PolygonId == areaMap.AreaId { |
| | | //logger.Info("--------------看看compareFlag的值和tableId和areaMap.args的长度:",compareFlag,tableIds,len(areaMap.args)) |
| | | for _, arg := range areaMap.args { |
| | | for _, arg := range areaMap.Args { |
| | | arg.Liker = arg.Liker[0:0] |
| | | //logger.Info("清空之后看看之前打的人脸标签变了没:") |
| | | //if args.RuleResult["face"] != nil && len(args.RuleResult["face"].([]FaceResult)) > 0 { |
| | |
| | | // } |
| | | //} |
| | | if compareFlag == 1 { |
| | | arg.fillLiker(nil, threshold) |
| | | fillLiker(nil, threshold, arg) |
| | | } |
| | | if compareFlag == 2 { |
| | | arg.fillLiker(tableIds, threshold) |
| | | fillLiker(tableIds, threshold, arg) |
| | | } |
| | | //logger.Info("-------------------成功给liker赋值,长度为:", len(arg.Liker)) |
| | | } |
| | | areaMap.filterData = areaMap.args |
| | | areaMap.FilterData = areaMap.Args |
| | | //logger.Info("=======第一次看args:",(areaMap.filterData)) |
| | | } |
| | | //logger.Info("-------------------------------人脸对比之后的目标数量",len(areaMap.args)) |
| | |
| | | } |
| | | |
| | | // 计算区域内的目标数量以及将相似度、占比、尺寸等打包 |
| | | func (a *AreaMap) CountAreaObjs(arg *SdkData) { |
| | | func CountAreaObjs(a *structure.AreaMap,arg *structure.SdkData) { |
| | | |
| | | a.targetNum = 0 |
| | | a.TargetNum = 0 |
| | | threshold := 80.0 // 相似度 |
| | | intersectionper := 0.2 // 占比 |
| | | size := 0.0 // 尺寸 |
| | | |
| | | areaPoints := Json2points(a.areaJson) |
| | | areaPoints := Json2points(a.AreaJson) |
| | | logger.Info("看看图片的width和height:",arg.ImageWidth,arg.ImageHeight) |
| | | widthScale := float64(arg.ImageWidth / 960) |
| | | heigthScale := float64(arg.ImageHeight / 540) |
| | | for _, obj := range arg.Photo { |
| | | //logger.Info("------------------看看sdkData:", arg.SdkName, "的Photo数据----------------", obj, "----顺便看看占比-----:", PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale)) |
| | | if threshold <= obj.Score && size <= float64(obj.Rects.Width*obj.Rects.Height) && intersectionper <= PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) { |
| | | // 这步要备齐表达式里所需要的所有参数 |
| | | a.targetNum++ |
| | | arg1 := Arg{obj.Id,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.Feature, obj.ThftRes, []*BaseInfo{}} |
| | | a.TargetNum++ |
| | | arg1 := structure.Arg{obj.Id,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), obj.IsYolo, obj.Rects, obj.Feature, obj.ThftRes, []*structure.BaseInfo{}} |
| | | //logger.Println("放进去的arg:-------", arg1) |
| | | a.args = append(a.args, &arg1) |
| | | a.filterData = append(a.filterData, &arg1) |
| | | a.Args = append(a.Args, &arg1) |
| | | a.FilterData = append(a.FilterData, &arg1) |
| | | } |
| | | } |
| | | logger.Info("区域是:",areaPoints,"区域内目标数量为:",a.targetNum,"---",len(a.filterData)) |
| | | a.time = time.Unix(time.Now().Unix(), 0).String()[11:16] |
| | | a.keepRight = arg.KeepRight |
| | | a.isStatic = arg.IsStatic |
| | | logger.Info("区域是:",areaPoints,"区域内目标数量为:",a.TargetNum,"---",len(a.FilterData)) |
| | | //for _,tar := range a.FilterData { |
| | | // logger.Info("具体目标的坐标为",tar.Id,tar.Location) |
| | | //} |
| | | a.Time = time.Unix(time.Now().Unix(), 0).String()[11:16] |
| | | a.KeepRight = arg.KeepRight |
| | | a.IsStatic = arg.IsStatic |
| | | //logger.Println("--------------------看看区域数据:",*a) |
| | | } |
| | | |
| | | // 把sdk从数据帧上提取的按照区域分类归置 |
| | | func SdkDataFormat(cameraId string, arg *SdkData, cameraPolygons []protomsg.CameraPolygon) { |
| | | func SdkDataFormat(cameraId string, arg *structure.SdkData, cameraPolygons []protomsg.CameraPolygon) { |
| | | logger.Info("==================================本sdkData中解出来的目标数据=======================================") |
| | | for _, photo := range arg.Photo { |
| | | logger.Info("--------解析出来的数据---", cameraId, arg.IpcId, photo.Rects, photo.Score) |
| | | } |
| | | for _, polygon := range cameraPolygons { |
| | | //logger.Println("++++++在这儿看一下区域啊:", polygon.Polygon) |
| | | areaMap := AreaMap{cameraId: cameraId, areaId: polygon.Id, areaJson: polygon.Polygon, triggerLine: polygon.TriggerLine, directionLine: polygon.DirectionLine} |
| | | areaMap := structure.AreaMap{CameraId: cameraId, AreaId: polygon.Id, AreaJson: polygon.Polygon, TriggerLine: polygon.TriggerLine, DirectionLine: polygon.DirectionLine} |
| | | // 为每个摄像机区域填充数据 |
| | | areaMap.CountAreaObjs(arg) |
| | | CountAreaObjs(&areaMap,arg) |
| | | arg.AreaMapList = append(arg.AreaMapList, &areaMap) |
| | | } |
| | | } |
| | |
| | | // case <-ctx.Done(): |
| | | // return |
| | | case data := <- sender: |
| | | logger.Info("比对进程入参:",data.TableIds,data.CompareThreshold) |
| | | bytes,err1 := proto.Marshal(data) |
| | | logger.Info("数据长度为:",len(bytes)) |
| | | if err1 != nil { |