| | |
| | | package ruleserver |
| | | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "plugin" |
| | | "ruleprocess/cache" |
| | | "ruleprocess/logger" |
| | | "ruleprocess/structure" |
| | | "sort" |
| | | "strconv" |
| | |
| | | |
| | | // 对单帧图像的判断 thisSdkDatas 当前传入的这帧数据,cacheSdkData 定时器里缓存的一帧数据 没有就返回nil (thisSdkDatas SdkDatas, cacheSdkDatas SdkDatas) |
| | | func Judge(args *structure.SdkDatas, message *protomsg.SdkMessage) { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | | logger.Error("规则模块儿的异常捕获:",err) |
| | | } |
| | | }() |
| | | if len(args.Sdkdata) > 0 { |
| | | // 拿到本摄像机的区域 |
| | | cameraPolygons := GetPolygons(args.CameraId) |
| | |
| | | } |
| | | } |
| | | |
| | | func RunRule(args *SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage, label Others) (bool,[]int) { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | | logger.Error("比对规则有误", err) |
| | | } |
| | | }() |
| | | logger.Info("+++++++++++规则开始运行+++++++++++++++++当前大规则--:", (*groupRule).GroupText) |
| | | //logger.Warn("传进去之后是什么德行:",args.RuleResult["yolo"]) |
| | | Compare(args, groupRule) |
| | | resultSplice := []*structure.LittleRuleResult{} |
| | | sdkNames := "" |
| | | polygonId := "" |
| | | // 先过完条件规则 |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | for _, sdkData := range args.Sdkdata { |
| | | // 根据规则的sdkId查出其对应的ipcId,用ipcId去找该比对的数据 |
| | | sdk, err := cache.GetSdkById(groupRule.Rules[j].SdkId) |
| | | if err != nil { |
| | | logger.Error("没查到sdk的信息---", err) |
| | | } |
| | | ipcId := sdk.IpcId |
| | | sdkName := sdk.SdkName |
| | | //logger.Info("规则的ipcId与sdkData的IpcId:", ipcId, "===", sdkData.IpcId) |
| | | if ipcId == sdkData.IpcId { |
| | | //logger.Info("当前走的规则是--:", sdkName, "---","") |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | ruleResult := CallSo(sdk.Id,groupRule.Rules[j],areaMap) |
| | | //ruleResult := filterRule(groupRule.Rules[j], areaMap) |
| | | if ruleResult.Result != "" { |
| | | logger.Info("条件规则结果:", ruleResult.Result) |
| | | // 如果结果为真,把这条规则中的区域置为有效 |
| | | if strings.Contains(ruleResult.Result, "true") { |
| | | areaMap.IsEffective = true |
| | | } |
| | | // 如果此结果为真且当前过的是yolo算法,应记下此规则所对应的sdkName,另外,还要去重 (后加:把此条触碰的区域id也记录下来) |
| | | if strings.Contains(ruleResult.Result, "true") && ipcId == "02D54B61-0F16-C604-8567-FC4BE493C523" && !strings.Contains(sdkNames, sdkName) { |
| | | sdkNames = sdkName + "," |
| | | polygonId = groupRule.Rules[j].PolygonId + "," |
| | | } |
| | | if strings.Contains(ruleResult.Result, "true") && ipcId == "02D54B61-0F16-C604-8567-FC4BE493C523" && !strings.Contains(polygonId, groupRule.Rules[j].PolygonId) { |
| | | polygonId = groupRule.Rules[j].PolygonId + "," |
| | | } |
| | | resultSplice = append(resultSplice, &ruleResult) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func CallSo(sdkId string,rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult{ |
| | | // 根据sdkId查出其对应的sdk的soName,调用相应so的Entrance方法 |
| | | var soName = "" |
| | | if sdkId == "812b674b-2375-4589-919a-5c1c3278a97e" { |
| | | soName = "face.so" |
| | | } else if sdkId == "812b674b-2375-4589-919a-5c1c3278a975"{ |
| | | soName = "intrusion.so" |
| | | } else if sdkId == "812b674b-2375-4589-919a-5c1c3278a976" { |
| | | soName = "personUnsual.so" |
| | | } else if sdkId == "812b674b-2375-4589-919a-5c1c3278a972" { |
| | | soName = "faceCompare.so" |
| | | } |
| | | p,err := plugin.Open("./algorithm/"+soName) |
| | | if err != nil { |
| | | panic(err) |
| | | } |
| | | f,err1 := p.Lookup("Entrance") |
| | | if err1 != nil { |
| | | panic("没有找到入口函数") |
| | | } |
| | | ruleResult := f.(func(rule *protomsg.Rule, am *structure.AreaMap)structure.LittleRuleResult)(rule,am) |
| | | return ruleResult |
| | | } |
| | | |
| | | func CallMiddleware(args *structure.SdkDatas,rule protomsg.GroupRule) ([]*structure.LittleRuleResult, string, string){ |
| | | p,err := plugin.Open("./algorithm/middleware.so") |
| | | if err != nil { |
| | |
| | | a,b,c := f.(func(args *structure.SdkDatas,rule protomsg.GroupRule)([]*structure.LittleRuleResult, string, string))(args,rule) |
| | | return a,b,c |
| | | } |
| | | func RunRule(args *structure.SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage, label structure.Others) bool { |
| | | func RunRule(args *structure.SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage, label structure.Others) (bool,[]int) { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | | logger.Error("比对规则有误", err) |
| | |
| | | //} |
| | | logger.Warn("___________________________________________________________________________终于走完万里长征") |
| | | // 把他们的位置数据也传下去 |
| | | locations := []structure.Rect{} |
| | | locations := []structure.TargetInfo{} |
| | | for _, sdkData := range args.Sdkdata { |
| | | if sdkData.IpcId == "02D54B61-0F16-C604-8567-FC4BE493C523" && sdkNames != "" { // 把yolo数据的各个目标的坐标输出方便后面画框 |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | |
| | | } |
| | | var labelTypes []int // 0为yolo标签,1为face标签 2为两者标签 |
| | | if sdkNames != "" { |
| | | args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]Result), Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, locations, polygonId, islink,label,}) |
| | | args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]structure.Result), structure.Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, locations, polygonId, islink,label,}) |
| | | labelTypes = append(labelTypes,0) |
| | | //logger.Info("-------------------yolo结果标签长度", len(args.RuleResult["yolo"].([]Result))) |
| | | } |
| | | if faceFlag { |
| | | args.RuleResult["face"] = append(args.RuleResult["face"].([]structure.FaceResult), structure.FaceResult{structure.Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, []structure.Rect{}, polygonId, islink, label,}, faces}) |
| | | args.RuleResult["face"] = append(args.RuleResult["face"].([]structure.FaceResult), structure.FaceResult{structure.Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, []structure.TargetInfo{}, polygonId, islink, label,}, faces}) |
| | | //logger.Info("-------------------face结果标签", len(args.RuleResult["face"].([]FaceResult))) |
| | | labelTypes = append(labelTypes,1) |
| | | } |
| | |
| | | return faces |
| | | } |
| | | |
| | | func putYolosToResult(am *structure.AreaMap) []structure.Rect { |
| | | locations := []structure.Rect{} |
| | | func putYolosToResult(am *structure.AreaMap) []structure.TargetInfo { |
| | | locations := []structure.TargetInfo{} |
| | | if len(am.FilterData) > 0 { |
| | | for _, data := range am.FilterData { |
| | | locations = append(locations, data.Location) |
| | | location := structure.TargetInfo{} |
| | | location.Rect = data.Location |
| | | location.TargetId = data.Id |
| | | location.TargetScore = data.Score |
| | | locations = append(locations, location) |
| | | } |
| | | } |
| | | //logger.Println("-----------------------------------------------听说你是空的?",faces) |
| | |
| | | // 倒是把打的组规则标签给去掉了啊 |
| | | for _,val := range labelTypes { |
| | | if val == 0 { |
| | | if len(args.RuleResult["yolo"].([]Result)) >= 1 { |
| | | lens := len(args.RuleResult["yolo"].([]Result))-1 |
| | | args.RuleResult["yolo"] = args.RuleResult["yolo"].([]Result)[0:lens] |
| | | if len(args.RuleResult["yolo"].([]structure.Result)) >= 1 { |
| | | lens := len(args.RuleResult["yolo"].([]structure.Result))-1 |
| | | args.RuleResult["yolo"] = args.RuleResult["yolo"].([]structure.Result)[0:lens] |
| | | } |
| | | } |
| | | if val == 1 { |
| | | if len(args.RuleResult["face"].([]FaceResult)) >= 1 { |
| | | lens := len(args.RuleResult["face"].([]FaceResult))-1 |
| | | args.RuleResult["face"] = args.RuleResult["face"].([]FaceResult)[0:lens] |
| | | if len(args.RuleResult["face"].([]structure.FaceResult)) >= 1 { |
| | | lens := len(args.RuleResult["face"].([]structure.FaceResult))-1 |
| | | args.RuleResult["face"] = args.RuleResult["face"].([]structure.FaceResult)[0:lens] |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | // 如果有持续时间条件维护开启一个定时器 |
| | | func duration(rule *protomsg.Rule, groupId string, am *structure.AreaMap, args *structure.SdkDatas, message *protomsg.SdkMessage) { |
| | | if rule.PolygonId == am.AreaId { // 首先规则所对应的区域id要跟区域数据的id对的上 配置的算法要对的上 |