panlei
2019-08-15 d62130814d09b4c0ad313979902ccefec6260ddf
ruleserver/readyDataForRule.go
@@ -50,10 +50,10 @@
   }
   logger.Debug("本机信息和server信息:", localConfig, serverIp, serverPort)
   bigCache.Init(dbTablePersons, serverIp, serverPort, localConfig.ServerId)
   //sock, err = req.NewSocket();
   //if err != nil {
   //   logger.Error("创建请求socket失败: %s", err.Error())
   //}
   sock, err = req.NewSocket();
   if err != nil {
      logger.Error("创建请求socket失败: %s", err.Error())
   }
}
type BaseInfo struct {
@@ -81,7 +81,7 @@
         taskGroup = task
      }
   }
   logger.Debug("当前数据帧要匹配的规则组:-------------------------")
   logger.Debug("当前数据帧要匹配的规则组:-------------------------","摄像机id:",cameraId,"任务id",taskId)
   for _,ruleGroup := range taskGroup.GroupRules{
      logger.Info(ruleGroup.GroupText)
   }
@@ -112,7 +112,7 @@
// 取出某个时间规则的第几天的规则段集合
func GetTimeById(id string, index int) []TimeRange {
   _, cameraTimeRule := cache.GetTimeRuleById(id)
   var timeRangeList []day
   var timeRangeList []Day
   err := json.Unmarshal([]byte(cameraTimeRule.TimeRule), &timeRangeList)
   if err != nil {
      logger.Error("取时间规则时反序列化错误!")
@@ -141,7 +141,7 @@
   Start string `json:"start"`
   End   string `json:"end"`
}
type day struct {
type Day struct {
   Day       int         `json:"day"`        // 标示当前星期几
   TimeRange []TimeRange `json:"time_range"` // 当天的几个时间段
}
@@ -166,23 +166,26 @@
}
// 给目标填充liker
func (arg *Arg) fillLiker(tableId []string, compareThreshold float32) {
   bytes := bigCache.GetComparePersonBaseInfo(tableId, arg.Feature, compareThreshold)
   //comArg := &protomsg.CompareArgs{
   //   TableIds:tableId,
   //   FaceFeature:arg.Feature,
   //   CompareThreshold:compareThreshold,
   //}
   //bytes := Push("tcp://192.168.1.182:40010",comArg,sock)
   var m map[string]float32
   err1 := json.Unmarshal(bytes, &m)
func (arg *Arg) FillLiker(tableId []string, compareThreshold float32) {
   //bytes := bigCache.GetComparePersonBaseInfo(tableId, arg.Feature, compareThreshold)
   comArg := &protomsg.CompareArgs{
      TableIds:tableId,
      FaceFeature:arg.Feature,
      CompareThreshold:compareThreshold,
      Source:false,
   }
   bytes := Push("tcp://192.168.1.182:40010",comArg,sock)
   var scResult protomsg.SdkCompareResult
   err1 := proto.Unmarshal(bytes, &scResult)
   if err1 != nil {
      logger.Error("getBaseInfo解压错误", err1)
   }
   //logger.Info("----------------------------------------map是", m)
   ids := []string{}
   for key, _ := range m {
      ids = append(ids, key)
   m := make(map[string]*protomsg.SdkCompareEach)
   for _,key := range scResult.CompareResult {
      ids = append(ids, key.Id)
      m[key.Id] = key
   }
   logger.Info("------------------------------------------------------------------------------------------------------------------------")
   //logger.Info("=====================人员id的集合为:",ids)
@@ -200,8 +203,8 @@
         if err != nil || len(table) == 0 {
            logger.Error("根据id查询底库信息出错!", err, "--返回值长度为:", len(table))
         }
         logger.Debug("看看这个base的对比值是多少:", Decimal(m[baseinfo.Id] * 100))
         base := BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id] * 100), PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved}
         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}
         //os.Exit(1)
         arg.Liker = append(arg.Liker, &base)
      }
@@ -213,7 +216,7 @@
func Compare(args *SdkDatas, groupRule *protomsg.GroupRule) {
   compareFlag := 0
   var tableIds []string
   var threshold float32 = 0.5 // 默认阈值为0.5
   var threshold float32 = 50 // 默认阈值为50
   // 看看是否有只配人脸比对算法但没有配对比库的规则,如果有,则比对对象为全部底库
   for j := 0; j < len(groupRule.Rules); j++ {
      if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972" { // 配了人脸比对
@@ -247,9 +250,9 @@
               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 {
@@ -260,14 +263,14 @@
                           }
                        }
                        if compareFlag == 1 {
                           arg.fillLiker(nil, threshold)
                           arg.FillLiker(nil, threshold)
                        }
                        if compareFlag == 2 {
                           arg.fillLiker(tableIds, threshold)
                           arg.FillLiker(tableIds, threshold)
                        }
                        //logger.Info("-------------------成功给liker赋值,长度为:", len(arg.Liker))
                     }
                     areaMap.filterData = areaMap.args
                     areaMap.FilterData = areaMap.Args
                     //logger.Info("=======第一次看args:",(areaMap.filterData))
                  }
                  //logger.Info("-------------------------------人脸对比之后的目标数量",len(areaMap.args))
@@ -282,29 +285,29 @@
// 计算区域内的目标数量以及将相似度、占比、尺寸等打包
func (a *AreaMap) CountAreaObjs(arg *SdkData) {
   a.targetNum = 0
   a.TargetNum = 0
   threshold := 0.0       // 相似度
   intersectionper := 0.2 // 占比
   size := 0.0            // 尺寸
   areaPoints := Json2points(a.areaJson)
   areaPoints := Json2points(a.AreaJson)
   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++
         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{}}
         //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))
   a.Time = time.Unix(time.Now().Unix(), 0).String()[11:16]
   a.KeepRight = arg.KeepRight
   a.IsStatic = arg.IsStatic
   //logger.Println("--------------------看看区域数据:",*a)
}
@@ -316,7 +319,7 @@
   }
   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 := AreaMap{CameraId: cameraId, AreaId: polygon.Id, AreaJson: polygon.Polygon, TriggerLine: polygon.TriggerLine, DirectionLine: polygon.DirectionLine}
      // 为每个摄像机区域填充数据
      areaMap.CountAreaObjs(arg)
      arg.AreaMapList = append(arg.AreaMapList, &areaMap)