panlei
2019-11-09 573a1e019fc00e171b7df7105fe69b414a490966
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
 
import (
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/logger.git"
    "github.com/knetic/govaluate"
    "ruleprocess/ruleserver"
    "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
        for k, _ := range ruleserver.TimeEleList {
            if k == rule.Id+""+strconv.Itoa(int(obj.Id)) {
                flag = false // 有就置为false
                logger.Info("有这个定时器,不再创建了:")
            }
        }
        if flag {
            timeEle := ruleserver.TimeElement{N: 10, InitN: 10, AlarmFlag: false, BufferFlag: 5} // 扔进去一个定时器元素
            ruleserver.TimeEleList[rule.Id+""+strconv.Itoa(int(obj.Id))] = &timeEle              // 定时器元素以小规则id和目标id为键
        }
    }
    return structure.LittleRuleResult{}
}
 
// 过滤规则先筛选出符合条件的目标数量
func filterRule(rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult {
    // 处理的都是yolo数据
    var args []*structure.Arg
    if rule.RuleWithPre == "&&" {
        args = am.FilterData
    } else {
        args = am.Args
    }
    // 先清空过滤后的数据,再往里塞本次过滤后的数据
    am.FilterData = am.FilterData[0:0]
    //logger.Debug("看看args:::::", args)
    for _, arg := range args {
        var formula string
        if rule.SdkArgAlias == "score" {
            formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式
            logger.Info("当前相似度小公式:", formula)
        } else if rule.SdkArgAlias == "proportion" {
            formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式
            logger.Info("当前占比小公式:", formula)
        } else {
            formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式
            logger.Info("当前尺寸小公式:", formula)
        }
        expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式
        result, _ := expression.Evaluate(nil)                      // 得到数学公式的结果
        if result.(bool) {
            am.FilterData = append(am.FilterData, arg) // 得到符合条件的过滤数据
        }
    }
    am.TargetNum = len(am.FilterData) // 把符合条件的目标数量更新到targetNum字段
    if am.TargetNum > 0 {
        return structure.LittleRuleResult{am.SdkName, rule.RuleWithPre + "" + "true", rule.Sort}
    } else {
        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)
}