| | |
| | | // 得到属于该摄像机的若干组任务的完整规则(跟每一条完整规则比较之后得出本张图像对于某个规则是否报警的结果。放进map,比如本帧图像的id,所碰撞成功的规则id) |
| | | args.RuleResult = make(map[string]interface{}) |
| | | args.RuleResult["yolo"] = []structure.Result{} |
| | | args.RuleResult["face"] = []structure.FaceResult{} |
| | | args.RuleResult["face"] = []structure.TargetResult{} |
| | | args.RuleResult["target"] = []structure.TargetResult{} |
| | | //logger.Warn("传进去之前是什么德行:",args.RuleResult["yolo"]) |
| | | if taskGroup != nil && len(taskGroup.GroupRules) > 0 { |
| | | // 先过独立,再过联动 |
| | |
| | | } |
| | | } |
| | | |
| | | func CallMiddleware(args *structure.SdkDatas,rule protomsg.GroupRule) (bool, string, string){ |
| | | func CallMiddleware(args *structure.SdkDatas,rule protomsg.GroupRule,lable *structure.Others,message *protomsg.SdkMessage) (bool, []*structure.Arg, string, string){ |
| | | p,err := plugin.Open("./algorithm/middleware.so") |
| | | if err != nil { |
| | | panic(err) |
| | |
| | | if err1 != nil { |
| | | panic("没有找到中间件入口函数") |
| | | } |
| | | a,b,c := f.(func(args *structure.SdkDatas,rule protomsg.GroupRule)(bool, string, string))(args,rule) |
| | | return a,b,c |
| | | a,b,c,d := f.(func(args *structure.SdkDatas,rule protomsg.GroupRule,label *structure.Others,message *protomsg.SdkMessage)(bool,[]*structure.Arg, string, string))(args,rule,lable,message) |
| | | return a,b,c,d |
| | | } |
| | | |
| | | func RunRule(args *structure.SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage, label structure.Others) (bool,[]int) { |
| | |
| | | result := false |
| | | sdkNames := "" |
| | | polygonId := "" |
| | | targets := []*structure.Arg{} // 符合条件的目标 |
| | | // 把一帧数据和一组规则发给算法部分,得出判断结果 |
| | | result,sdkNames,polygonId = CallMiddleware(args,*groupRule) |
| | | |
| | | result,targets,sdkNames,polygonId = CallMiddleware(args,*groupRule,&label,message) |
| | | logger.Info("符合条件的目标数据:",targets) |
| | | if result { |
| | | // 最后过持续时间等时间维度的条件 把时间规则位置调整到这个位置是为了缓存数据 |
| | | // 最后过持续时间等时间维度的条件 把时间规则位置调整到这个位置是为了缓存数据 !!!!!ps: 对画面中单个目标做定时器的不用再过画面定时器 |
| | | cacheId := "" |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | for _, sdkData := range args.Sdkdata { |
| | |
| | | } |
| | | 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.TargetInfo{}, polygonId, islink,label,}, faces}) |
| | | args.RuleResult["face"] = append(args.RuleResult["face"].([]structure.TargetResult), structure.TargetResult{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) |
| | | } |
| | |
| | | } |
| | | } |
| | | if k == "face" { |
| | | tempMap[k] = []structure.FaceResult{} |
| | | for _, res := range result.([]structure.FaceResult) { |
| | | tempMap[k] = append(tempMap[k].([]structure.FaceResult), res) |
| | | tempMap[k] = []structure.TargetResult{} |
| | | for _, res := range result.([]structure.TargetResult) { |
| | | tempMap[k] = append(tempMap[k].([]structure.TargetResult), res) |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | if k == "face" { |
| | | tempMap[k] = []structure.FaceResult{} |
| | | for _, res := range result.([]structure.FaceResult) { |
| | | tempMap[k] = append(tempMap[k].([]structure.FaceResult), res) |
| | | tempMap[k] = []structure.TargetResult{} |
| | | for _, res := range result.([]structure.TargetResult) { |
| | | tempMap[k] = append(tempMap[k].([]structure.TargetResult), res) |
| | | } |
| | | } |
| | | } |
| | |
| | | args.RuleResult["yolo"].([]structure.Result)[i].Others.LinkCache = label.LinkCache |
| | | } |
| | | } |
| | | for i := 0; i < len(args.RuleResult["face"].([]structure.FaceResult)); i++ { |
| | | if args.RuleResult["face"].([]structure.FaceResult)[i].RuleGroupId == groupRule.GroupId { // 把联动数据追加上 |
| | | args.RuleResult["face"].([]structure.FaceResult)[i].Others.LinkCache = label.LinkCache |
| | | for i := 0; i < len(args.RuleResult["face"].([]structure.TargetResult)); i++ { |
| | | if args.RuleResult["face"].([]structure.TargetResult)[i].RuleGroupId == groupRule.GroupId { // 把联动数据追加上 |
| | | args.RuleResult["face"].([]structure.TargetResult)[i].Others.LinkCache = label.LinkCache |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | 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] |
| | | if len(args.RuleResult["face"].([]structure.TargetResult)) >= 1 { |
| | | lens := len(args.RuleResult["face"].([]structure.TargetResult))-1 |
| | | args.RuleResult["face"] = args.RuleResult["face"].([]structure.TargetResult)[0:lens] |
| | | } |
| | | } |
| | | } |