panlei
2019-11-09 573a1e019fc00e171b7df7105fe69b414a490966
algorithm/static/static.go
@@ -8,7 +8,21 @@
   "ruleprocess/structure"
   "strconv"
)
//个体静止算法
var StaticMap = make(map[string]CameraArea)
type CameraArea struct {
   targets  []Obj
   duration int
   cache    structure.ResultMsg
}
type Obj struct {
   id           string
   location     []structure.Rect
   staticStatus int
}
func Entrance(rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult {
   for _,obj := range am.FilterData {
      var flag bool = true
@@ -63,3 +77,24 @@
      return structure.LittleRuleResult{am.SdkName, rule.RuleWithPre + "" + "false", rule.Sort}
   }
}
// 判断两个矩形的重合度,把面积更大的做分母
func PgsInterPercent(pgpts []structure.Point, box structure.Rect, widthScale float64, heightScale float64) (percent float64) {
   areapts, areaBox := ruleserver.GetLocation(box, 10)
   var count = 0
   for _, pts := range areapts {
      if ruleserver.PintIsInPolygon(pts, pgpts, widthScale, heightScale) {
         count++
      }
   }
   perInterBox := float64(count) / float64(len(areapts)) // 重合面积占矩形的比例
   areaInter := perInterBox * areaBox
   areaPg := ruleserver.ComputePolygonArea(pgpts)
   perInterPg := areaInter / areaPg // 重合面积占多边形区域的比例
   // 哪个占的比例小按哪个计算,比如人站起来了,大框套住了小框
   if perInterBox < perInterPg {
      return (perInterBox * 100)
   }
   return (perInterPg * 100)
}