| | |
| | | cameraPolygons := GetPolygons(args.CameraId) |
| | | // 把所有的sdk提取的数据都按所属摄像机的区域归置 |
| | | logger.Debug("当前摄像机id为:",message.Cid,"当前摄像机执行的任务是:",message.Tasklab.Taskname,"--任务id为:",message.Tasklab.Taskid) |
| | | for _, arg := range args.Sdkdata { |
| | | SdkDataFormat(args.CameraId, arg, cameraPolygons) |
| | | } |
| | | CallReadyData(args,cameraPolygons) |
| | | // 跑本摄像机的所有规则组 一组一组跑 |
| | | taskGroup := GetRuleGroup(args.CameraId, args.TaskId) // 本摄像机本任务下所有规则组 |
| | | //logger.Println("看下摄像机下的任务组:",taskRuleList) |
| | | // 得到属于该摄像机的若干组任务的完整规则(跟每一条完整规则比较之后得出本张图像对于某个规则是否报警的结果。放进map,比如本帧图像的id,所碰撞成功的规则id) |
| | | args.RuleResult = make(map[string]interface{}) |
| | | args.RuleResult["yolo"] = []structure.Result{} |
| | | args.RuleResult["face"] = []structure.TargetResult{} |
| | | args.RuleResult["target"] = []structure.TargetResult{} |
| | | args.RuleResult["face"] = []structure.Result{} |
| | | args.RuleResult["target"] = []structure.Result{} |
| | | //logger.Warn("传进去之前是什么德行:",args.RuleResult["yolo"]) |
| | | if taskGroup != nil && len(taskGroup.GroupRules) > 0 { |
| | | // 先过独立,再过联动 |
| | |
| | | return a,b,c |
| | | } |
| | | |
| | | func CallReadyData(args *structure.SdkDatas,cameraPolygons []protomsg.CameraPolygon) { |
| | | p,err := plugin.Open("./algorithm/middleware.so") |
| | | if err != nil { |
| | | panic(err) |
| | | } |
| | | f,err1 := p.Lookup("ReadData") |
| | | if err1 != nil { |
| | | panic("没有找到中间件的数据准备函数") |
| | | } |
| | | f.(func(args *structure.SdkDatas,cameraPolygons []protomsg.CameraPolygon)())(args,cameraPolygons) |
| | | } |
| | | |
| | | 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 { |
| | |
| | | result := false |
| | | sdkNames := "" |
| | | polygonId := "" |
| | | targets := []*structure.Arg{} // 符合条件的目标 |
| | | |
| | | // 把一帧数据和一组规则发给算法部分,得出判断结果 |
| | | result,sdkNames,polygonId = CallMiddleware(args,*groupRule,&label,message) |
| | | for _, sdkData := range args.Sdkdata { |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | targets = append(targets,areaMap.AlarmObj...) |
| | | for _,obj := range areaMap.AlarmObj { |
| | | logger.Info("个体静止的目标",obj.Id,obj.Location) |
| | | } |
| | | } |
| | | } |
| | | //logger.Info("符合条件的目标数据:",targets) |
| | | |
| | | if result { |
| | | // 最后过持续时间等时间维度的条件 把时间规则位置调整到这个位置是为了缓存数据 !!!!!ps: 对画面中单个目标做定时器的不用再过画面定时器 |
| | | cacheId := "" |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | for _, sdkData := range args.Sdkdata { |
| | | sdk, err := cache.GetSdkById(groupRule.Rules[j].SdkId) |
| | |
| | | if ipcId == sdkData.IpcId { |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | // 去开启一个定时器 |
| | | cacheid := duration(groupRule.Rules[j], groupRule.GroupId, areaMap, args, message) |
| | | if cacheid != "" { |
| | | cacheId = cacheid |
| | | } |
| | | duration(groupRule.Rules[j], groupRule.GroupId, areaMap, args, message,label) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 进行定时器的处理和判断 |
| | | timeFlag := TimerAlarm(&label, groupRule.GroupId, result) |
| | | if timeFlag == "01" || timeFlag == "10" || timeFlag == "11" || cacheId != ""{ // 没有定时器或者满足定时器条件 |
| | | if timeFlag == "01" || timeFlag == "10" || timeFlag == "11"{ // 没有定时器或者满足定时器条件 |
| | | // 打人脸标签和yolo标签 |
| | | // 最后成功报警才把符合条件的人脸数据塞进结果标签里 |
| | | // 配了人脸的算法才把人脸的数据甩出来打标签 |
| | | faces := []structure.Arg{} |
| | | faces := []*structure.Arg{} |
| | | faceFlag := false |
| | | for j := 0; j < len(groupRule.Rules); j++ { |
| | | if groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || groupRule.Rules[j].SdkId == "812b674b-2375-4589-919a-5c1c3278a972" { |
| | |
| | | //} |
| | | logger.Warn("___________________________________________________________________________终于走完万里长征") |
| | | // 把他们的位置数据也传下去 |
| | | locations := []structure.TargetInfo{} |
| | | yolos := []*structure.Arg{} |
| | | for _, sdkData := range args.Sdkdata { |
| | | if sdkData.IpcId == "02D54B61-0F16-C604-8567-FC4BE493C523" && sdkNames != "" { // 把yolo数据的各个目标的坐标输出方便后面画框 |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | if areaMap.IsEffective { |
| | | locations = append(locations, putYolosToResult(areaMap)...) |
| | | yolos = append(yolos, putYolosToResult(areaMap)...) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | logger.Debug("------locations的内容:", locations) |
| | | logger.Debug("------locations的内容:", yolos) |
| | | // 处理目标定时数据 |
| | | targets := []*structure.Arg{} |
| | | for _, sdkData := range args.Sdkdata { |
| | | if sdkData.IpcId == "02D54B61-0F16-C604-8567-FC4BE493C523" && sdkNames != "" { // 输出目标数据 |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | if areaMap.IsEffective { |
| | | targets = append(targets, putTargetsToResult(areaMap)...) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 车辆目标统计 |
| | | cars := []*structure.Arg{} |
| | | for _, sdkData := range args.Sdkdata { |
| | | if sdkData.IpcId == "91d923ef-6200-4549-ab1b-8e773e85d729" && sdkNames != "" { // 把车牌数据的各个目标的坐标输出方便后面画框 |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | if areaMap.IsEffective { |
| | | cars = append(cars, putFaceToResult(areaMap, cars)...) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | var islink bool |
| | | if groupRule.SetType == "linkTask" { |
| | | islink = true |
| | |
| | | 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}) |
| | | if sdkNames != "" && len(targets) == 0 { |
| | | args.RuleResult["yolo"] = append(args.RuleResult["yolo"].([]structure.Result), structure.Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, yolos, 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.TargetResult), structure.TargetResult{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.Result), structure.Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, faces, polygonId, islink,label}) |
| | | //logger.Info("-------------------face结果标签", len(args.RuleResult["face"].([]FaceResult))) |
| | | labelTypes = append(labelTypes,1) |
| | | } |
| | | // 给持续时间的第一张赋予缓存数据(遍历复制) |
| | | if cacheId != "" { // 有这帧数据的缓存 |
| | | tempMap := make(map[string]interface{}) |
| | | for k, result := range args.RuleResult { |
| | | if k == "yolo" { |
| | | tempMap[k] = []structure.Result{} |
| | | for _, res := range result.([]structure.Result) { |
| | | tempMap[k] = append(tempMap[k].([]structure.Result), res) |
| | | } |
| | | } |
| | | if k == "face" { |
| | | tempMap[k] = []structure.TargetResult{} |
| | | for _, res := range result.([]structure.TargetResult) { |
| | | tempMap[k] = append(tempMap[k].([]structure.TargetResult), res) |
| | | } |
| | | } |
| | | } |
| | | rw.Lock() |
| | | TimeEleList[cacheId].CacheSdkData.RuleResult = tempMap |
| | | rw.Unlock() |
| | | if len(targets) > 0 { |
| | | args.RuleResult["target"] = append(args.RuleResult["target"].([]structure.Result), structure.Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, targets, polygonId, islink,label}) |
| | | logger.Info("-------------------目标持续结果标签", len(args.RuleResult["target"].([]structure.Result))) |
| | | //labelTypes = append(labelTypes,2) |
| | | } |
| | | if len(cars) > 0 { |
| | | args.RuleResult["plate"] = append(args.RuleResult["plate"].([]structure.Result), structure.Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, cars, polygonId, islink,label}) |
| | | logger.Info("-------------------车牌结果标签", len(args.RuleResult["plate"].([]structure.Result))) |
| | | //labelTypes = append(labelTypes,2) |
| | | } |
| | | // 给持续时间的第一张赋予缓存数据(遍历复制) |
| | | //if cacheId != "" { // 有这帧数据的缓存 |
| | | // tempMap := make(map[string]interface{}) |
| | | // for k, result := range args.RuleResult { |
| | | // if k == "yolo" { |
| | | // tempMap[k] = []structure.Result{} |
| | | // for _, res := range result.([]structure.Result) { |
| | | // tempMap[k] = append(tempMap[k].([]structure.Result), res) |
| | | // } |
| | | // } |
| | | // if k == "face" { |
| | | // tempMap[k] = []structure.Result{} |
| | | // for _, res := range result.([]structure.Result) { |
| | | // tempMap[k] = append(tempMap[k].([]structure.Result), res) |
| | | // } |
| | | // } |
| | | // } |
| | | // rw.Lock() |
| | | // TimeEleList[cacheId].CacheSdkData.RuleResult = tempMap |
| | | // rw.Unlock() |
| | | //} |
| | | |
| | | return true,labelTypes |
| | | } else { |
| | |
| | | // 结果为假时也要走,有杀死定时器的操作 |
| | | TimerAlarm(&label, groupRule.GroupId, result) |
| | | //fmt.Println(timeFlag) |
| | | logger.Info("不符合规则") |
| | | return false,[]int{} |
| | | } |
| | | } |
| | | |
| | | func putFaceToResult(am *structure.AreaMap, faceList []structure.Arg) []structure.Arg { |
| | | faces := []structure.Arg{} |
| | | func putFaceToResult(am *structure.AreaMap, faceList []*structure.Arg) []*structure.Arg { |
| | | faces := []*structure.Arg{} |
| | | if len(am.FilterData) > 0 { |
| | | for _, data := range am.FilterData { |
| | | flag := true |
| | |
| | | } |
| | | } |
| | | if flag { |
| | | faces = append(faces, *data) |
| | | faces = append(faces, data) |
| | | } |
| | | } |
| | | } |
| | |
| | | return faces |
| | | } |
| | | |
| | | func putYolosToResult(am *structure.AreaMap) []structure.TargetInfo { |
| | | locations := []structure.TargetInfo{} |
| | | func putYolosToResult(am *structure.AreaMap) []*structure.Arg { |
| | | locations := []*structure.Arg{} |
| | | if len(am.FilterData) > 0 { |
| | | for _, data := range am.FilterData { |
| | | location := structure.TargetInfo{} |
| | | location.Rect = data.Location |
| | | location.TargetId = data.Id |
| | | location.TargetScore = data.Score |
| | | locations = append(locations, location) |
| | | } |
| | | locations = am.FilterData |
| | | } |
| | | //logger.Println("-----------------------------------------------听说你是空的?",faces) |
| | | return locations |
| | | } |
| | | |
| | | func putTargetsToResult(am *structure.AreaMap) []*structure.Arg { |
| | | locations := []*structure.Arg{} |
| | | if len(am.AlarmObj) > 0 { |
| | | locations = am.AlarmObj |
| | | } |
| | | //logger.Println("-----------------------------------------------听说你是空的?",faces) |
| | | return locations |
| | | } |
| | | // 联动任务的处理 |
| | | func LinkTask(args *structure.SdkDatas, groupRule *protomsg.GroupRule, taskId string, message *protomsg.SdkMessage, label structure.Others) { |
| | | // new一个定时器,如果以此groupId为标志的定时器不存在的话 |
| | |
| | | } |
| | | } |
| | | if k == "face" { |
| | | tempMap[k] = []structure.TargetResult{} |
| | | for _, res := range result.([]structure.TargetResult) { |
| | | tempMap[k] = append(tempMap[k].([]structure.TargetResult), res) |
| | | tempMap[k] = []structure.Result{} |
| | | for _, res := range result.([]structure.Result) { |
| | | tempMap[k] = append(tempMap[k].([]structure.Result), res) |
| | | } |
| | | } |
| | | } |
| | |
| | | args.RuleResult["yolo"].([]structure.Result)[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 |
| | | for i := 0; i < len(args.RuleResult["face"].([]structure.Result)); i++ { |
| | | if args.RuleResult["face"].([]structure.Result)[i].RuleGroupId == groupRule.GroupId { // 把联动数据追加上 |
| | | args.RuleResult["face"].([]structure.Result)[i].Others.LinkCache = label.LinkCache |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | if val == 1 { |
| | | 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] |
| | | if len(args.RuleResult["face"].([]structure.Result)) >= 1 { |
| | | lens := len(args.RuleResult["face"].([]structure.Result))-1 |
| | | args.RuleResult["face"] = args.RuleResult["face"].([]structure.Result)[0:lens] |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | // 如果有持续时间条件维护开启一个定时器 |
| | | func duration(rule *protomsg.Rule, groupId string, am *structure.AreaMap, args *structure.SdkDatas, message *protomsg.SdkMessage) string{ |
| | | cacheId := "" |
| | | func duration(rule *protomsg.Rule, groupId string, am *structure.AreaMap, args *structure.SdkDatas, message *protomsg.SdkMessage, label structure.Others){ |
| | | // cacheId := "" |
| | | if rule.PolygonId == am.AreaId { // 首先规则所对应的区域id要跟区域数据的id对的上 配置的算法要对的上 |
| | | if rule.SdkArgAlias == "duration" { // |
| | | if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a977" { // 排除对画面中单个目标的算法,个体静止以及靠右行这种 |
| | | return |
| | | } |
| | | if rule.SdkArgAlias == "duration" { |
| | | //logger.Info("当前小规则是:---------", rule) |
| | | // 先看看定时器元素队列中是否有这条规则的定时器,如果有就不能再次创建了 |
| | | rw.Lock() |
| | |
| | | } |
| | | |
| | | if flag { |
| | | m := make(map[string]interface{}) |
| | | m["yolo"] = []structure.Result{} |
| | | m["yolo"] = append(m["yolo"].([]structure.Result), structure.Result{args.TaskId, "", "", true, 0, "", am.FilterData, am.AreaJson, false,label}) |
| | | timeLength, _ := strconv.Atoi(rule.SdkArgValue) |
| | | timeEle := TimeElement{N: timeLength, InitN: timeLength, AlarmFlag: false, BufferFlag: 10, CacheSdkData: structure.ResultMsg{message, nil}} // 扔进去一个定时器元素(并缓存当前画面帧数据) |
| | | timeEle := TimeElement{N: timeLength, InitN: timeLength, AlarmFlag: false, BufferFlag: 10, CacheSdkData: structure.ResultMsg{message, m}} // 扔进去一个定时器元素(并缓存当前画面帧数据) |
| | | //TimeEleList = make(map[string]timeElement) |
| | | TimeEleList[groupId+"+"+rule.Id] = &timeEle // 定时器元素以当前持续时间小规则id为键 |
| | | logger.Info("创建了计数器") |
| | | cacheId = groupId+"+"+rule.Id |
| | | //cacheId = groupId+"+"+rule.Id |
| | | } |
| | | rw.Unlock() |
| | | } |
| | | } |
| | | return cacheId |
| | | return |
| | | } |
| | | |