| | |
| | | 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) |
| | | // 把所有的sdk提取的数据都按所属摄像机的区域归置 |
| | | //logger.Debug("当前摄像机id为:",message.Cid,"当前摄像机执行的任务是:",message.Tasklab.Taskname) |
| | | logger.Debug("当前摄像机id为:",message.Cid,"当前摄像机执行的任务是:",message.Tasklab.Taskname,"--任务id为:",message.Tasklab.Taskid) |
| | | for _, arg := range args.Sdkdata { |
| | | SdkDataFormat(args.CameraId, arg, cameraPolygons) |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | func RunRule1(args *structure.SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage, label structure.Others) bool { |
| | | 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.Info("face标签的长度:",len(faces)) |
| | | //for _,face := range faces { |
| | | // //logger.Debug("————————————————________________看看人脸的坐标:",face.Location) |
| | | //} |
| | | 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 { |
| | |
| | | } else { |
| | | islink = false |
| | | } |
| | | var labelTypes []int // 0为yolo标签,1为face标签 2为两者标签 |
| | | if sdkNames != "" { |
| | | 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,}) |
| | | 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 true |
| | | return true,labelTypes |
| | | } else { |
| | | return false |
| | | return false,[]int{} |
| | | } |
| | | |
| | | } else { |
| | | // 结果为假时也要走,有时候为假的状态反转数据也需要记录下来 |
| | | // 结果为假时也要走,有杀死定时器的操作 |
| | | TimerAlarm(&label, groupRule.GroupId, result.(bool)) |
| | | //fmt.Println(timeFlag) |
| | | return false |
| | | return false,[]int{} |
| | | } |
| | | } else { |
| | | return false |
| | | return false,[]int{} |
| | | } |
| | | } |
| | | |
| | |
| | | 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) |
| | |
| | | } |
| | | } |
| | | // 往数组里赋值 |
| | | isOk := RunRule(args, groupRule, taskId, message, label) |
| | | isOk,labelTypes := RunRule(args, groupRule, taskId, message, label) |
| | | if isOk { |
| | | logger.Info("这帧图像在任务下的一整条规则下(联动任务下就是跟本摄像机像相关的小规则)的判断结果为true") |
| | | // 根据cameraId去更新或者插入结果,然后判断是否数组是否可以得出报警的结论 |
| | |
| | | } else { |
| | | logger.Warn("数组不圆满不打标签") |
| | | // 倒是把打的组规则标签给去掉了啊 |
| | | lens := len(args.RuleResult["yolo"].([]structure.Result)) - 1 |
| | | args.RuleResult["yolo"] = args.RuleResult["yolo"].([]structure.Result)[0:lens] |
| | | for _,val := range labelTypes { |
| | | if val == 0 { |
| | | 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"].([]structure.FaceResult)) >= 1 { |
| | | lens := len(args.RuleResult["face"].([]structure.FaceResult))-1 |
| | | args.RuleResult["face"] = args.RuleResult["face"].([]structure.FaceResult)[0:lens] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } else { // 没有报警, |
| | | //logger.Info("这帧图像在任务下的一整条规则下(联动任务下就是跟本摄像机像相关的小规则)的判断结果为false") |