File was renamed from algorithm/car/car.go |
| | |
| | | switch rule.SdkArgAlias { |
| | | case "score": |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("当前相似度小公式:", formula) |
| | | logger.Info("相似度小公式:", formula) |
| | | case "proportion": |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("占比公式:", formula) |
| | |
| | | case "nDirection": |
| | | formula = strconv.Itoa(int(arg.Car.NDirection)) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("车牌运动方向小公式:", formula) |
| | | case "nTime": |
| | | formula = strconv.Itoa(int(arg.Car.NTime)) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("识别耗时小公式:", formula) |
| | | case "nCarBright": |
| | | formula = strconv.Itoa(int(arg.Car.NCarBright)) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("车的亮度小公式:", formula) |
| | |
| | | //logger.Info("-----------------------人脸过滤的args里的数量:", len(args)) |
| | | for _, arg := range args { |
| | | var formula string |
| | | if rule.SdkArgAlias == "score" { |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前相似度小公式:", formula) |
| | | } else if rule.SdkArgAlias == "proportion" { |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前占比小公式:", formula) |
| | | } else { |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前尺寸小公式:", formula) |
| | | switch rule.SdkArgAlias { |
| | | case "score": |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("相似度小公式:", formula) |
| | | case "proportion": |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("占比公式:", formula) |
| | | case "size": |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("尺寸小公式:", formula) |
| | | } |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | |
| | | |
| | | // 过滤规则先筛选出符合条件的目标数量 |
| | | func filterRule1(rule *protomsg.Rule, am *structure.AreaMap) structure.LittleRuleResult { |
| | | |
| | | if rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a97e" || rule.SdkId == "812b674b-2375-4589-919a-5c1c3278a972" { |
| | | // 处理的是人脸算法 如果这条规则配置的是人脸算法,过滤完条件之后直接得出结果,因为肯定没有数量条件,自己拼接 |
| | | //logger.Info("规则的算法id和区域的算法id:", rule.SdkId, "===", am.sdkId) |
| | |
| | | //logger.Info("-----------------------人脸过滤的args里的数量:", len(args)) |
| | | for _, arg := range args { |
| | | var formula string |
| | | if rule.SdkArgAlias == "score" { |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前相似度小公式:", formula) |
| | | } else if rule.SdkArgAlias == "proportion" { |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前占比小公式:", formula) |
| | | } else { |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前尺寸小公式:", formula) |
| | | switch rule.SdkArgAlias { |
| | | case "score": |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("相似度小公式:", formula) |
| | | case "proportion": |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("占比公式:", formula) |
| | | case "size": |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("尺寸小公式:", formula) |
| | | } |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | |
| | | //logger.Debug("看看args:::::", args) |
| | | for _, arg := range args { |
| | | var formula string |
| | | if rule.SdkArgAlias == "score" { |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前相似度小公式:", formula) |
| | | } else if rule.SdkArgAlias == "proportion" { |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前占比小公式:", formula) |
| | | } else { |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前尺寸小公式:", formula) |
| | | switch rule.SdkArgAlias { |
| | | case "score": |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("相似度小公式:", formula) |
| | | case "proportion": |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("占比公式:", formula) |
| | | case "size": |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("尺寸小公式:", formula) |
| | | } |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | |
| | | // 这步要备齐表达式里所需要的所有参数 |
| | | a.TargetNum++ |
| | | uuid := uuid.NewV4().String() |
| | | arg1 := structure.Arg{obj.Id,uuid,obj.Score, ruleserver.PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), a.AreaJson,obj.IsYolo, obj.Rects, obj.Car,obj.Feature, obj.ThftRes, []*structure.BaseInfo{},"",structure.ResultMsg{}} |
| | | arg1 := structure.Arg{obj.Id,uuid,obj.Score, ruleserver.PgsInterPercent(areaPoints, obj.Rects, widthScale, heigthScale), float64(obj.Rects.Width * obj.Rects.Height), a.AreaJson,obj.Type, obj.Rects, obj.Car,obj.Feature, obj.ThftRes, []*structure.BaseInfo{},"",structure.ResultMsg{}} |
| | | //logger.Println("放进去的arg:-------", arg1) |
| | | a.Args = append(a.Args, &arg1) |
| | | a.FilterData = append(a.FilterData, &arg1) |
| | |
| | | for _, info := range yoloParam.Infos { |
| | | if info.Typ == 0 { |
| | | //logger.Debug("-------------yolo的坐标有几个",info.RcObj) |
| | | photoMap := structure.PhotoMap{Rects: rectFormat(info.RcObj), Score: float64(info.Prob) * 100, IsYolo: true,Id:strconv.Itoa(int(info.ObjID))} |
| | | photoMap := structure.PhotoMap{Rects: rectFormat(info.RcObj), Score: float64(info.Prob) * 100, Type: "yolo",Id:strconv.Itoa(int(info.ObjID))} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | yoloNum++ |
| | | } |
| | |
| | | logger.Info("--------------追踪之后人脸的个数:", len(faceParam.Faces)) |
| | | for _, info := range faceParam.Faces { |
| | | //logger.Info("_______________________________________________第一次看相似值:",info.Pos.FAngle.Confidence*100) |
| | | photoMap := structure.PhotoMap{Id: strconv.Itoa(int(info.Pos.FaceID)) , Rects: rectFormat(info.Pos.RcFace), Score: float64(info.Pos.FAngle.Confidence * 100), IsYolo: false, ThftRes: *(info.Result), Feature: info.Feats} |
| | | photoMap := structure.PhotoMap{Id: strconv.Itoa(int(info.Pos.FaceID)) , Rects: rectFormat(info.Pos.RcFace), Score: float64(info.Pos.FAngle.Confidence * 100), Type: "face", ThftRes: *(info.Result), Feature: info.Feats} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | |
| | | } |
| | | for _, info := range plateIDResult.Result { |
| | | logger.Info("接收车牌数据:",info) |
| | | photoMap := structure.PhotoMap{Score: float64(info.NConfidence),Rects: rectFormat(info.RcLocation), IsYolo: false, Car:info} |
| | | photoMap := structure.PhotoMap{Score: float64(info.NConfidence),Rects: rectFormat(info.RcLocation), Type: "plate", Car:info} |
| | | arg.Photo = append(arg.Photo, photoMap) |
| | | } |
| | | args.Sdkdata = append(args.Sdkdata, &arg) |
| | |
| | | //logger.Debug("看看args:::::", args) |
| | | for _, arg := range args { |
| | | var formula string |
| | | if rule.SdkArgAlias == "score" { |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前相似度小公式:", formula) |
| | | } else if rule.SdkArgAlias == "proportion" { |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前占比小公式:", formula) |
| | | } else { |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue // 得到字符串公式 |
| | | logger.Info("当前尺寸小公式:", formula) |
| | | switch rule.SdkArgAlias { |
| | | case "score": |
| | | formula = strconv.FormatFloat(arg.Score, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("相似度小公式:", formula) |
| | | case "proportion": |
| | | formula = strconv.FormatFloat(arg.Proportion, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("占比公式:", formula) |
| | | case "size": |
| | | formula = strconv.FormatFloat(arg.Size, 'f', -1, 64) + " " + rule.Operator + " " + rule.SdkArgValue |
| | | logger.Info("尺寸小公式:", formula) |
| | | } |
| | | expression, _ := govaluate.NewEvaluableExpression(formula) // 得到数学公式 |
| | | result, _ := expression.Evaluate(nil) // 得到数学公式的结果 |
| | |
| | | "github.com/satori/go.uuid" |
| | | "strconv" |
| | | ) |
| | | |
| | | const ( |
| | | PREFIX_CAMERA = "CAMERA_" |
| | | PREFIX_POLYGON = "POLYGON_" |
| | |
| | | PREFIX_RULE = "RULE_" |
| | | SERVER_KEY = "SERVERINFO" |
| | | PREFIX_SDK = "SDK_" |
| | | PREFIX_DIC = "DIC_" |
| | | PREFIX_SO = "SO" |
| | | ) |
| | | |
| | | var cMap *shardmap.ShardMap |
| | | |
| | | |
| | | func Init(initChan chan bool,dbIp string,surveyPort int,pubSubPort int){ |
| | | cMap = shardmap.New(uint8(32)) |
| | |
| | | initSdks() //初始化sdk列表信息 |
| | | |
| | | initSoData() |
| | | |
| | | initDictionary() // 初始化字典 |
| | | |
| | | initChan <- true |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | func initDictionary() { |
| | | var api dbapi.DicApi |
| | | flag, dics := api.FindByType("") |
| | | if flag { |
| | | for key, dics := range dics.(map[string][]Dic) { |
| | | for _,dic := range dics { |
| | | cMap.Set(PREFIX_DIC+key+dic.value, dic) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | func initCameraTaskRules(){ |
| | | var api dbapi.CameraTaskArgsApi |
| | | all := api.FindAll() |
| | |
| | | return sdk,errors.New("sdk not found") |
| | | } |
| | | } |
| | | // 获取字典值 |
| | | func GetDic(key string) (value string) { |
| | | obj, b := cMap.Get(PREFIX_SDK + key) |
| | | if b { |
| | | return obj.(Dic).value |
| | | } else { |
| | | return "" |
| | | } |
| | | } |
| | | |
| | | |
| | | func initSoData() { |
| | | var api dbapi.SoApi |
| | |
| | | return sdk,errors.New("sdk not found") |
| | | } |
| | | } |
| | | |
| | | type Dic struct { |
| | | Id string |
| | | value string |
| | | Name string |
| | | Type string |
| | | Description string |
| | | Sort int |
| | | Parent_id string |
| | | } |
| | |
| | | Content string `json:"content"` |
| | | AlarmRules []AlarmRule `json:"alarmRules"` |
| | | LikeDate string `json:"likeDate"` |
| | | Sex string `json:"sex"` |
| | | Age int32 `json:"age"` |
| | | AgeDescription string `json:"ageDescription"` |
| | | Race string `json:"race"` |
| | | SmileLevel int32 `json:"smileLevel"` |
| | | BeautyLevel int32 `json:"beautyLevel"` |
| | | ShowLable string `json:"showLable"` |
| | | OtherLable string `json:"otherLable"` |
| | | FaceFeature string `json:"faceFeature"` |
| | | PicSmUrl []string `json:"picSmUrl"` |
| | | VideoUrl string `json:"videoUrl"` |
| | |
| | | Content string `json:"content"` |
| | | AlarmRules []AlarmRule `json:"alarmRules"` |
| | | LikeDate string `json:"likeDate"` |
| | | Sex string `json:"sex"` |
| | | Age int32 `json:"age"` |
| | | AgeDescription string `json:"ageDescription"` |
| | | Race string `json:"race"` |
| | | SmileLevel int32 `json:"smileLevel"` |
| | | BeautyLevel int32 `json:"beautyLevel"` |
| | | Lable string `json:"lable"` |
| | | FaceFeature string `json:"faceFeature"` |
| | | PicSmUrl []string `json:"picSmUrl"` |
| | | VideoUrl string `json:"videoUrl"` |
| | |
| | | LinkInfo string `json:"linkInfo"` |
| | | } |
| | | |
| | | // 一个face对多个规则组的归置人脸的结构体 |
| | | type FaceAndRules struct { |
| | | // 一个obj对多个规则组的归置人脸的结构体 可用于人脸 可用于车牌 |
| | | type ObjAndRules struct { |
| | | structure.Arg |
| | | rules []structure.Result |
| | | } |
| | |
| | | InsertTarget(msg) |
| | | } |
| | | |
| | | // 往es中插入人脸数据 |
| | | // 往es中插入人脸类型数据 |
| | | func InsertFace(msg structure.ResultMsg) { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.Result)) > 0 { |
| | | logger.Info("往ES插人脸数据") |
| | | faces := []*FaceAndRules{} |
| | | faces = PutFace(faces, msg) |
| | | if (msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.Result)) > 0) || (msg.RuleResult["plate"] != nil && len(msg.RuleResult["plate"].([]structure.Result)) > 0) { |
| | | for key, results := range msg.RuleResult { |
| | | if key == "face" || key == "plate" { |
| | | logger.Info("往ES插人脸数据(或车牌数据)") |
| | | faces := []*ObjAndRules{} |
| | | faces = PutFace(faces, results.([]structure.Result)) |
| | | //logger.Info("整理后的数据:",faces) |
| | | if faces != nil { |
| | | var imgMaxUrl string = "" |
| | |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | alarmRules := []AlarmRule{} |
| | | //os.Exit(1) |
| | | for _, faceResult := range face.rules { |
| | | alarm := ChangeToString(faceResult.DefenceState, faceResult.AlarmLevel) |
| | | alarmRules = append(alarmRules, AlarmRule{faceResult.RuleGroupId, alarm, faceResult.RuleText, faceResult.DefenceState, ""}) |
| | |
| | | imgMaxUrl = bigPhotoUrl["fileUrl"].(string) |
| | | picTime = i.Timestamp |
| | | } |
| | | sex := "" |
| | | logger.Info(sex) |
| | | if face.ThftRes.Gender == 1 { |
| | | sex = "男" |
| | | } else { |
| | | sex = "女" |
| | | } |
| | | race := getRaceString(face.ThftRes.Race) |
| | | ageDescription := getDescription(face.ThftRes.Age) |
| | | logger.Info(ageDescription) |
| | | lable,lableAttach := Feature2Jsonstr(*face) |
| | | var target = new(Target) |
| | | target.TargetId = face.Id |
| | | target.TargetScore = face.Score |
| | |
| | | time.Now().Format("2006-01-02 15:04:05"), |
| | | alarmRules, |
| | | time.Now().Format("2006-01-02 15:04:05"), // 只检测,没有比对时间 |
| | | sex, //暂改为人脸id strconv.FormatUint(face.Id, 10) |
| | | face.ThftRes.Age, |
| | | ageDescription, // 暂改为分值fmt.Sprintf("%.2f",face.Score) |
| | | race, |
| | | face.ThftRes.Smile, |
| | | face.ThftRes.Beauty, |
| | | lable, |
| | | lableAttach, |
| | | base64.StdEncoding.EncodeToString(face.Feature), |
| | | []string{resp["fileUrl"].(string)}, |
| | | "", |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 归置人脸 |
| | | func PutFace(faces []*FaceAndRules, msg structure.ResultMsg) []*FaceAndRules { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.Result)) > 0 { |
| | | for _, faceResult := range msg.RuleResult["face"].([]structure.Result) { |
| | | faces = hebingFace(faces, faceResult) |
| | | func PutFace(objs []*ObjAndRules, resutls []structure.Result) []*ObjAndRules { |
| | | for _, faceResult := range resutls { |
| | | objs = hebingFace(objs, faceResult) |
| | | } |
| | | return faces |
| | | } else { |
| | | return nil |
| | | return objs |
| | | } |
| | | } |
| | | func hebingFace(faces []*FaceAndRules, faceResult structure.Result) []*FaceAndRules { |
| | | func hebingFace(objs []*ObjAndRules, faceResult structure.Result) []*ObjAndRules { |
| | | for _, arg := range faceResult.AlarmObj { |
| | | // 拿到每一张人脸 |
| | | //logger.Info("归置人脸时相似者的数量:", len(arg.Liker)) |
| | | flag := false |
| | | for _, face := range faces { |
| | | for _, face := range objs { |
| | | //for _, lik := range face.Liker { |
| | | // //logger.Warn("--------合并人脸时相似者:", lik.PersonId, lik.TableName) |
| | | //} |
| | |
| | | } |
| | | } |
| | | if !flag { |
| | | faces = append(faces, &FaceAndRules{*arg, []structure.Result{faceResult}}) |
| | | objs = append(objs, &ObjAndRules{*arg, []structure.Result{faceResult}}) |
| | | } |
| | | } |
| | | return faces |
| | | return objs |
| | | } |
| | | |
| | | // 往es中插入yolo数据 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 获取本机ip |
| | | func GetLocalIP() (ipv4 string, err error) { |
| | | var ( |
| | |
| | | return "" |
| | | } |
| | | } |
| | | |
| | | //获取年龄描述 |
| | | func getDescription(age int32) string { |
| | | ageInfo := "青年" |
| | |
| | | race = "黑人" |
| | | } |
| | | return race |
| | | } |
| | | |
| | | func Feature2Jsonstr(obj ObjAndRules) (string,string) { |
| | | var lable string |
| | | var lableAttach string |
| | | switch obj.Type { |
| | | case "face": |
| | | sex := "" |
| | | if obj.ThftRes.Gender == 1 { |
| | | sex = "男" |
| | | } else { |
| | | sex = "女" |
| | | } |
| | | race := getRaceString(obj.ThftRes.Race) |
| | | ageDescription := getDescription(obj.ThftRes.Age) |
| | | lable = sex+" / "+ageDescription+" / "+race+" / " |
| | | lableAttach = strconv.Itoa(int(obj.ThftRes.Age))+"岁"+" / "+"微笑值:"+strconv.Itoa(int(obj.ThftRes.Smile))+" / "+"颜值:"+strconv.Itoa(int(obj.ThftRes.Beauty)) |
| | | |
| | | case "plate": |
| | | // 车牌运动方向,0 unknown, 1 left, 2 right, 3 up, 4 down |
| | | lable = obj.Car.License+" / "+cache.GetDic("nColor"+strconv.Itoa(int(obj.Car.NColor)))+"车牌"+" / "+ |
| | | cache.GetDic("nCarColor"+strconv.Itoa(int(obj.Car.NCarColor)))+"车辆"+" / "+ cache.GetDic("nCarLogo"+strconv.Itoa(int(obj.Car.NCarLogo)))+" / "+cache.GetDic("nCarLogo"+strconv.Itoa(int(obj.Car.NCarType))) |
| | | lableAttach = cache.GetDic("nDirection"+strconv.Itoa(int(obj.Car.NDirection)))+" / "+"车牌置信度:"+strconv.Itoa(int(obj.Car.NConfidence))+" / "+ |
| | | "车牌亮度:"+strconv.Itoa(int(obj.Car.NBright))+" / "+"车的亮度:"+strconv.Itoa(int(obj.Car.NCarBright))+" / "+"识别时间:"+strconv.Itoa(int(obj.Car.NTime)) |
| | | } |
| | | return lable,lableAttach |
| | | } |
| | | |
| | | func msg2PersonVideo(msg structure.ResultMsg) *LinkInfo { |
| | |
| | | "", |
| | | alarmRules, |
| | | time.Now().Format("2006-01-02 15:04:05"), // 只检测,没有比对时间 |
| | | "", //暂改为人脸id strconv.FormatUint(face.Id, 10) |
| | | 0, |
| | | "", // 暂改为分值fmt.Sprintf("%.2f",face.Score) |
| | | "", |
| | | 0, |
| | | 0, |
| | | "", |
| | | []string{resp["fileUrl"].(string)}, |
| | | "", |
| | |
| | | |
| | | 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标签 |
| | | // 最后成功报警才把符合条件的人脸数据塞进结果标签里 |
| | | // 配了人脸的算法才把人脸的数据甩出来打标签 |
| | |
| | | // 车辆目标统计 |
| | | cars := []*structure.Arg{} |
| | | for _, sdkData := range args.Sdkdata { |
| | | if sdkData.IpcId == "91d923ef-6200-4549-ab1b-8e773e85d729" && sdkNames != "" { // 把yolo数据的各个目标的坐标输出方便后面画框 |
| | | if sdkData.IpcId == "91d923ef-6200-4549-ab1b-8e773e85d729" && sdkNames != "" { // 把车牌数据的各个目标的坐标输出方便后面画框 |
| | | for _, areaMap := range sdkData.AreaMapList { |
| | | if areaMap.IsEffective { |
| | | cars = append(cars, putYolosToResult(areaMap)...) |
| | | cars = append(cars, putFaceToResult(areaMap, cars)...) |
| | | } |
| | | } |
| | | } |
| | |
| | | //labelTypes = append(labelTypes,2) |
| | | } |
| | | if len(cars) > 0 { |
| | | args.RuleResult["car"] = append(args.RuleResult["car"].([]structure.Result), structure.Result{taskId, sdkNames, groupRule.GroupId, groupRule.DefenceState, groupRule.AlarmLevel, groupRule.GroupText, cars, polygonId, islink,label}) |
| | | logger.Info("-------------------目标持续结果标签", len(args.RuleResult["target"].([]structure.Result))) |
| | | 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() |
| | | } |
| | | //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 { |
| | |
| | | } |
| | | |
| | | // 如果有持续时间条件维护开启一个定时器 |
| | | 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.SdkId == "812b674b-2375-4589-919a-5c1c3278a977" { // 排除对画面中单个目标的算法,个体静止以及靠右行这种 |
| | | return "" |
| | | return |
| | | } |
| | | if rule.SdkArgAlias == "duration" { |
| | | //logger.Info("当前小规则是:---------", rule) |
| | |
| | | } |
| | | |
| | | 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,*lable}) |
| | | 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 |
| | | } |
| | | |
| | |
| | | Proportion float64 // 区域内的目标的占比 |
| | | Size float64 // 区域内的目标的尺寸 |
| | | AreaJson string // 所属区域 |
| | | IsYolo bool // 是否是yolo数据 |
| | | Type string // 记载数据类型 |
| | | Location Rect // 记下每个目标的位置参数,最后给结果装配目标数据的时候用的到 |
| | | Car *protomsg.PlateID // 车辆参数 |
| | | Feature []byte |
| | |
| | | Id string |
| | | Rects Rect // 矩形区域参数 |
| | | Score float64 // 相似度得分(有多大程度像一个目标。人脸,人体或车等等) |
| | | IsYolo bool // 是否是yolo数据 |
| | | Type string // 记载数据类型 |
| | | ThftRes protomsg.ThftResult |
| | | Feature []byte |
| | | Car *protomsg.PlateID |