---
panlei
2019-12-16 b9d95191e0326a1a75f3809d75b94638c47c3d43
ruleserver/readyDataForRule.go
@@ -3,12 +3,12 @@
import (
   "basic.com/dbapi.git"
   "basic.com/pubsub/protomsg.git"
   logger "github.com/jeanphorn/log4go"
   "encoding/base64"
   "encoding/json"
   "errors"
   "fmt"
   "basic.com/valib/logger.git"
   "github.com/golang/protobuf/proto"
   uuid "github.com/satori/go.uuid"
   "math"
   "nanomsg.org/go-mangos"
   "nanomsg.org/go-mangos/protocol/req"
@@ -116,9 +116,10 @@
// 给目标填充liker
func fillLiker(tableId []string, compareThreshold float32,arg *structure.Arg) {
   //bytes := bigCache.GetComparePersonBaseInfo(tableId, arg.Feature, compareThreshold)
   decodeBytes, _ := base64.StdEncoding.DecodeString(arg.Feature)
   comArg := &protomsg.CompareArgs{
      TableIds:tableId,
      FaceFeature:arg.Feature,
      FaceFeature:decodeBytes,
      CompareThreshold:compareThreshold,
      Source:false,
   }
@@ -157,7 +158,7 @@
         if err != nil || len(table) == 0 {
            logger.Error("根据id查询底库信息出错!", err, "--返回值长度为:", len(table))
         }
         logger.Debug("看看这个base的对比值是多少:", Decimal(m[baseinfo.Id].CompareScore))
         //logger.Debug("看看这个base的对比值是多少:", Decimal(m[baseinfo.Id].CompareScore))
         base := structure.BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id].CompareScore), TargetId: baseinfo.Id, TargetName: baseinfo.PersonName, TargetPicUrl: baseinfo.PersonPicUrl, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved,DbLabel: baseinfo.PhoneNum+"/"+baseinfo.Sex+"/"+baseinfo.IdCard,}
         //os.Exit(1)
         arg.Liker = append(arg.Liker, &base)
@@ -184,7 +185,7 @@
         if groupRule.Rules[j].SdkArgAlias == "cmpThreshold" {
            v2, err := strconv.ParseFloat(groupRule.Rules[j].SdkArgValue, 32)
            if err != nil {
               logger.Error("string转float32失败!")
               //logger.Error("string转float32失败!")
            }
            threshold = float32(v2)
         }
@@ -193,15 +194,15 @@
   // 为了测试作下弊,直接让其比对全部底库
   //compareFlag = 1
   if compareFlag == 0 {
      logger.Info("没有配置对比底库参数")
      //logger.Info("没有配置对比底库参数")
      return
   }
   logger.Debug("=====配置的阈值为:", threshold)
   //logger.Debug("=====配置的阈值为:", threshold)
   for j := 0; j < len(groupRule.Rules); j++ {
      if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972" {
         for _, sdkData := range args.Sdkdata {
            if sdkData.IpcId == "A8B73405-373D-4F23-CED2-A617EBD7EC55" { // 搜索到人脸检测的sdkdata 现在关于人脸的只有他一个sdk,全找他
               logger.Info("============================================进行人脸对比")
               //logger.Info("============================================进行人脸对比")
               for _, areaMap := range sdkData.AreaMapList {
                  // 拿区域中每个人脸特征值去对比,填充其liker
                  if groupRule.Rules[j].PolygonId == areaMap.AreaId {
@@ -229,48 +230,48 @@
}
// 计算区域内的目标数量以及将相似度、占比、尺寸等打包
func CountAreaObjs(a *structure.AreaMap,arg *structure.SdkData) {
   a.TargetNum = 0
   threshold := 80.0       // 相似度
   intersectionper := 20.0 // 占比
   size := 0.0            // 尺寸
   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  obj.Score >= threshold && float64(obj.Rects.Width*obj.Rects.Height) >= size && PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) >= intersectionper {
         // 这步要备齐表达式里所需要的所有参数
         a.TargetNum++
         uuid := uuid.NewV4().String()
         arg1 := structure.Arg{obj.Id,uuid,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), a.AreaJson,obj.Type, obj.Rects, obj.Car,obj.Feature, obj.ThftRes, []*structure.BaseInfo{},"",structure.ResultMsg{}}
         //logger.Println("放进去的arg:-------", 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]
   //logger.Println("--------------------看看区域数据:",*a)
}
// 把sdk从数据帧上提取的按照区域分类归置
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 := structure.AreaMap{CameraId: cameraId, AreaId: polygon.Id, AreaJson: polygon.Polygon, TriggerLine: polygon.TriggerLine, DirectionLine: polygon.DirectionLine}
      // 为每个摄像机区域填充数据
      CountAreaObjs(&areaMap,arg)
      arg.AreaMapList = append(arg.AreaMapList, &areaMap)
   }
}
//func CountAreaObjs(a *structure.AreaMap,arg *structure.SdkData) {
//
//   a.TargetNum = 0
//   threshold := 80.0       // 相似度
//   intersectionper := 20.0 // 占比
//   size := 0.0            // 尺寸
//
//   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  obj.Score >= threshold && float64(obj.Rects.Width*obj.Rects.Height) >= size && PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale) >= intersectionper {
//         // 这步要备齐表达式里所需要的所有参数
//         a.TargetNum++
//         uuid := uuid.NewV4().String()
//         arg1 := structure.Arg{obj.Id,uuid,obj.Score, PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), a.AreaJson,obj.Type, obj.Rects, obj.Car,obj.Feature, obj.ThftRes, []*structure.BaseInfo{},"",structure.ResultMsg{}}
//         //logger.Println("放进去的arg:-------", 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]
//   //logger.Println("--------------------看看区域数据:",*a)
//}
//
//// 把sdk从数据帧上提取的按照区域分类归置
//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 := structure.AreaMap{CameraId: cameraId, AreaId: polygon.Id, AreaJson: polygon.Polygon, TriggerLine: polygon.TriggerLine, DirectionLine: polygon.DirectionLine}
//      // 为每个摄像机区域填充数据
//      CountAreaObjs(&areaMap,arg)
//      arg.AreaMapList = append(arg.AreaMapList, &areaMap)
//   }
//}
func Push(data *protomsg.CompareArgs,sock mangos.Socket) []byte{
   //var sock mangos.Socket
@@ -344,19 +345,16 @@
            logger.Info("序列化失败:",err1)
         }
         logger.Debug("推送数据")
         //bytes := []byte("ndfasojdfaidsos")
         if err = sock.Send(bytes); err != nil {
            logger.Error("推送socket发送数据失败: %s", err.Error())
            //os.Exit(1)
         }
         if msg, err = sock.Recv(); err != nil {
            logger.Error("接收响应失败: %s", err.Error())
            //os.Exit(1)
         }
         logger.Debug("数据推送成功!收到响应,数据长度为:",len(msg))
         receiver <- msg
      default:
         time.Sleep(time.Millisecond * 10)
      }
   }
}