| | |
| | | |
| | | // 往es中插入人脸数据 |
| | | func InsertFace(msg structure.ResultMsg) { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.TargetResult)) > 0 { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.Result)) > 0 { |
| | | logger.Info("往ES插人脸数据") |
| | | faces := []*FaceAndRules{} |
| | | faces = PutFace(faces, msg) |
| | |
| | | // 上传大图 |
| | | if imgMaxUrl == "" { |
| | | bigPhotoUrl := make(map[string]interface{}) |
| | | bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.TargetResult), weedfsUrl) |
| | | bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.Result), weedfsUrl) |
| | | logger.Debug("========大图路径:", bigPhotoUrl) |
| | | imgMaxUrl = bigPhotoUrl["fileUrl"].(string) |
| | | picTime = i.Timestamp |
| | |
| | | |
| | | // 归置人脸 |
| | | func PutFace(faces []*FaceAndRules, msg structure.ResultMsg) []*FaceAndRules { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.TargetResult)) > 0 { |
| | | for _, faceResult := range msg.RuleResult["face"].([]structure.TargetResult) { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.Result)) > 0 { |
| | | for _, faceResult := range msg.RuleResult["face"].([]structure.Result) { |
| | | faces = hebingFace(faces, faceResult) |
| | | } |
| | | return faces |
| | |
| | | return nil |
| | | } |
| | | } |
| | | func hebingFace(faces []*FaceAndRules, faceResult structure.TargetResult) []*FaceAndRules { |
| | | for _, arg := range faceResult.Args { |
| | | func hebingFace(faces []*FaceAndRules, faceResult structure.Result) []*FaceAndRules { |
| | | for _, arg := range faceResult.AlarmObj { |
| | | // 拿到每一张人脸 |
| | | //logger.Info("归置人脸时相似者的数量:", len(arg.Liker)) |
| | | flag := false |
| | |
| | | //} |
| | | if arg.Id == face.Id { |
| | | flag = true |
| | | face.rules = append(face.rules, faceResult.Result) |
| | | face.rules = append(face.rules, faceResult) |
| | | // 相似者去重归并 |
| | | for _, liker := range arg.Liker { |
| | | flag1 := true |
| | |
| | | } |
| | | } |
| | | if !flag { |
| | | faces = append(faces, &FaceAndRules{arg, []structure.Result{faceResult.Result}}) |
| | | faces = append(faces, &FaceAndRules{*arg, []structure.Result{faceResult}}) |
| | | } |
| | | } |
| | | return faces |
| | |
| | | } |
| | | } |
| | | // 装配目标信息数据 |
| | | for _, target := range yoloResult.Location { |
| | | for _, target := range yoloResult.AlarmObj { |
| | | // 去重添加 |
| | | var flag = true |
| | | for _, selectTarget := range targetInfos { |
| | | if strconv.FormatUint(target.TargetId, 10) == selectTarget.TargetId { |
| | | if strconv.FormatUint(target.Id, 10) == selectTarget.TargetId { |
| | | flag = false |
| | | break |
| | | } |
| | | } |
| | | if flag { |
| | | var target1 = new(Target) |
| | | target1.TargetId = strconv.FormatUint(target.TargetId, 10) |
| | | target1.TargetScore = target.TargetScore |
| | | target1.TargetLocation = Points{TopLeft: Point{target.X, target.Y}, BottomRight: Point{target.X + target.Width, target.Y + target.Height}} |
| | | target1.TargetId = strconv.FormatUint(target.Id, 10) |
| | | target1.TargetScore = target.Score |
| | | target1.TargetLocation = Points{TopLeft: Point{target.Location.X, target.Location.Y}, BottomRight: Point{target.Location.X + target.Location.Width, target.Location.Y + target.Location.Height}} |
| | | targetInfos = append(targetInfos, *target1) |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | // 装配目标信息数据 |
| | | for _, target := range yoloResult.Location { |
| | | for _, target := range yoloResult.AlarmObj { |
| | | // 去重添加 |
| | | var flag = true |
| | | for _, selectTarget := range targetInfos { |
| | | if strconv.FormatUint(target.TargetId, 10) == selectTarget.TargetId { |
| | | if strconv.FormatUint(target.Id, 10) == selectTarget.TargetId { |
| | | flag = false |
| | | break |
| | | } |
| | | } |
| | | if flag { |
| | | var target1 = new(Target) |
| | | target1.TargetId = strconv.FormatUint(target.TargetId, 10) |
| | | target1.TargetScore = target.TargetScore |
| | | target1.TargetLocation = Points{TopLeft: Point{target.X, target.Y}, BottomRight: Point{target.X + target.Width, target.Y + target.Height}} |
| | | target1.TargetId = strconv.FormatUint(target.Id, 10) |
| | | target1.TargetScore = target.Score |
| | | target1.TargetLocation = Points{TopLeft: Point{target.Location.X, target.Location.Y}, BottomRight: Point{target.Location.X + target.Location.Width, target.Location.Y + target.Location.Height}} |
| | | targetInfos = append(targetInfos, *target1) |
| | | } |
| | | } |
| | |
| | | CameraAddr string |
| | | TaskId string |
| | | Time string |
| | | Persons []structure.TargetResult |
| | | Persons []structure.Result |
| | | DefenceLevel []int32 |
| | | } |
| | | // 把数据装配到label |
| | | func (label *Label)DataFormatToLabel(result structure.ResultMsg) { |
| | | logger.Debug("face结果:",result.RuleResult["face"] != nil && len(result.RuleResult["face"].([]structure.TargetResult)) > 0) |
| | | logger.Debug("face结果:",result.RuleResult["face"] != nil && len(result.RuleResult["face"].([]structure.Result)) > 0) |
| | | logger.Debug("yolo结果:",result.RuleResult["yolo"] != nil && len(result.RuleResult["yolo"].([]structure.Result)) > 0) |
| | | if (result.RuleResult["face"] != nil && len(result.RuleResult["face"].([]structure.TargetResult)) > 0) || (result.RuleResult["yolo"] != nil && len(result.RuleResult["yolo"].([]structure.Result)) > 0) { // 得有人脸或者yolo规则才可以 |
| | | if (result.RuleResult["face"] != nil && len(result.RuleResult["face"].([]structure.Result)) > 0) || (result.RuleResult["yolo"] != nil && len(result.RuleResult["yolo"].([]structure.Result)) > 0) { // 得有人脸或者yolo规则才可以 |
| | | |
| | | // 先判断一下数据带的规则标签是否有报警的可以推送的 |
| | | flag := false |
| | |
| | | flag = true |
| | | } |
| | | } |
| | | if flag || (result.RuleResult["face"] != nil && len(result.RuleResult["face"].([]structure.TargetResult)) > 0){ |
| | | if flag || (result.RuleResult["face"] != nil && len(result.RuleResult["face"].([]structure.Result)) > 0){ |
| | | logger.Info("---------------标签过滤器赋值") |
| | | label.CameraId = result.Cid |
| | | camera, err := cache.GetCameraById(result.Cid) |
| | |
| | | label.CameraAddr = camera.Addr |
| | | label.TaskId = result.Tasklab.Taskid |
| | | label.Time = time.Now().Format("2006-01-02 15:04:05") |
| | | if result.RuleResult["face"] != nil && len(result.RuleResult["face"].([]structure.TargetResult)) > 0 { |
| | | for _,faceGroup := range result.RuleResult["face"].([]structure.TargetResult) { |
| | | if result.RuleResult["face"] != nil && len(result.RuleResult["face"].([]structure.Result)) > 0 { |
| | | for _,faceGroup := range result.RuleResult["face"].([]structure.Result) { |
| | | label.Persons = append(label.Persons,faceGroup) |
| | | label.DefenceLevel = append(label.DefenceLevel,faceGroup.AlarmLevel) |
| | | } |
| | |
| | | func baseJudge(label *Label, rule *protomsg.EventPushRule) string { |
| | | if rule.RuleValue == "all" { |
| | | for _, personGroup := range label.Persons { |
| | | for _, arg := range personGroup.Args { |
| | | for _, arg := range personGroup.AlarmObj { |
| | | if len(arg.Liker) > 0 { |
| | | logger.Info("满足全部底库规则") |
| | | return "true" |
| | |
| | | return "false" |
| | | } else { |
| | | for _, personGroup := range label.Persons { |
| | | for _, arg := range personGroup.Args { |
| | | for _, arg := range personGroup.AlarmObj { |
| | | for _, liker := range arg.Liker { |
| | | formula := "'" + liker.TableId + "'" + rule.Operator + "'" + rule.RuleValue + "'" |
| | | expression, err := govaluate.NewEvaluableExpression(formula); |
| | |
| | | //是否符合人员规则 |
| | | func personJudge(label *Label, rule *protomsg.EventPushRule) string { |
| | | for _, personGroup := range label.Persons { |
| | | for _, person := range personGroup.Args { |
| | | for _, person := range personGroup.AlarmObj { |
| | | formula := "" |
| | | if rule.TopicArg == "sex" { |
| | | formula = strconv.Itoa(int(person.ThftRes.Gender)) + rule.Operator + rule.RuleValue |
| | |
| | | } |
| | | if rule.TopicArg == "monitorLevel" { |
| | | if rule.RuleValue == "all" { |
| | | if len(personGroup.Args) > 0 { |
| | | if len(personGroup.AlarmObj) > 0 { |
| | | logger.Info("符合人员等级为全部的规则") |
| | | return "true" |
| | | } |
| | |
| | | |
| | | a.TargetNum = 0 |
| | | threshold := 80.0 // 相似度 |
| | | intersectionper := 0.2 // 占比 |
| | | intersectionper := 20.0 // 占比 |
| | | size := 0.0 // 尺寸 |
| | | |
| | | areaPoints := Json2points(a.AreaJson) |
| | |
| | | // 得到属于该摄像机的若干组任务的完整规则(跟每一条完整规则比较之后得出本张图像对于某个规则是否报警的结果。放进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 { |
| | | // 先过独立,再过联动 |
| | |
| | | // 打人脸标签和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) |
| | | var islink bool |
| | | if groupRule.SetType == "linkTask" { |
| | | islink = true |
| | |
| | | } |
| | | 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, 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 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) |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | 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 := "" |
| | | if rule.PolygonId == am.AreaId { // 首先规则所对应的区域id要跟区域数据的id对的上 配置的算法要对的上 |
| | | if rule.SdkArgAlias == "duration" { // |
| | | if rule.SdkArgAlias == "duration" && rule.SdkId != "812b674b-2375-4589-919a-5c1c3278a977"{ // 排除对画面中单个目标的算法,个体静止以及靠右行这种 |
| | | //logger.Info("当前小规则是:---------", rule) |
| | | // 先看看定时器元素队列中是否有这条规则的定时器,如果有就不能再次创建了 |
| | | rw.Lock() |
| | |
| | | Size float64 // 区域内的目标的尺寸 |
| | | AreaJson string // 所属区域 |
| | | IsYolo bool // 是否是yolo数据 |
| | | Location Rect // 记下每个目标的位置参数,最后给结果装配人脸数据的时候用的到 |
| | | Location Rect // 记下每个目标的位置参数,最后给结果装配目标数据的时候用的到 |
| | | Feature []byte |
| | | ThftRes protomsg.ThftResult |
| | | Liker []*BaseInfo |
| | |
| | | DefenceState bool // 是否布防 |
| | | AlarmLevel int32 // 报警等级 |
| | | RuleText string // 文字版规则组 |
| | | Location []TargetInfo // 目标的坐标 |
| | | //Location []TargetInfo // 目标的坐标 |
| | | AlarmObj []*Arg // 报警的目标数据 打算废掉上面的Location |
| | | AlarmPolygon string // 触发的报警框 |
| | | IsLink bool // 是否是联动任务 |
| | | Others |
| | |
| | | Rect |
| | | TargetId uint64 |
| | | TargetScore float64 |
| | | } |
| | | |
| | | // 过规则库打上的标签 |
| | | type TargetResult struct { |
| | | Result |
| | | Args []Arg |
| | | } |
| | | type LittleRuleResult struct { |
| | | SdkName string // 记录下此结果是哪个sdk的结果 |