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) |
| | |
| | | ) |
| | | |
| | | // 人员异常算法 |
| | | func Entrance(rule *protomsg.Rule, am *structure.AreaMap,lable *structure.Others,args *structure.SdkDatas,message *protomsg.SdkMessage) structure.LittleRuleResult { |
| | | func Entrance(rule *protomsg.Rule, am *structure.AreaMap, lable *structure.Others, args *structure.SdkDatas, message *protomsg.SdkMessage) structure.LittleRuleResult { |
| | | if rule.PolygonId == am.AreaId { // 首先这条规则得是这个算法的规则,其次规则所对应的区域id要跟区域数据的id对的上 |
| | | logger.Debug("---------走了人员异常算法",rule.Id,rule.SdkArgAlias,rule.Operator,rule.SdkArgValue,am.AreaId) |
| | | logger.Debug("---------走了人员异常算法", rule.Id, rule.SdkArgAlias, rule.Operator, rule.SdkArgValue, am.AreaId) |
| | | if rule.SdkArgAlias == "score" || rule.SdkArgAlias == "proportion" || rule.SdkArgAlias == "size" || rule.SdkArgAlias == "" { // 判断的是相似值,占比,尺寸等过滤条件,如果再有,还可以再加 |
| | | return filterRule(rule, am) |
| | | } else if rule.SdkArgAlias == "objCount" { |
| | |
| | | //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_CAMERA = "CAMERA_" |
| | | PREFIX_POLYGON = "POLYGON_" |
| | | PREFIX_TIME = "TIME_" |
| | | PREFIX_RULE = "RULE_" |
| | | SERVER_KEY = "SERVERINFO" |
| | | PREFIX_SDK = "SDK_" |
| | | PREFIX_SO = "SO" |
| | | PREFIX_TIME = "TIME_" |
| | | 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){ |
| | | func Init(initChan chan bool, dbIp string, surveyPort int, pubSubPort int) { |
| | | cMap = shardmap.New(uint8(32)) |
| | | urlSurvey := "tcp://" + dbIp + ":" + strconv.Itoa(surveyPort) |
| | | urlPubSub := "tcp://" + dbIp + ":" + strconv.Itoa(pubSubPort) |
| | |
| | | initCacheData(initChan) |
| | | |
| | | peers, _ := client.Peers() |
| | | for b := range peers{ |
| | | fmt.Println("peerMsg:",b) |
| | | for b := range peers { |
| | | fmt.Println("peerMsg:", b) |
| | | updateData(b) |
| | | } |
| | | } |
| | | |
| | | func initCacheData(initChan chan bool) { |
| | | |
| | | initPolygons()//初始化摄像机多边形缓存 |
| | | initPolygons() //初始化摄像机多边形缓存 |
| | | |
| | | initTimeRules()//初始化时间规则缓存 |
| | | initTimeRules() //初始化时间规则缓存 |
| | | |
| | | initCameraTaskRules()//初始化摄像机任务规则缓存 |
| | | initCameraTaskRules() //初始化摄像机任务规则缓存 |
| | | |
| | | initCamera()//初始化摄像机信息 |
| | | initCamera() //初始化摄像机信息 |
| | | |
| | | initServerInfo()//初始化服务器配置信息 |
| | | initServerInfo() //初始化服务器配置信息 |
| | | |
| | | initSdks() //初始化sdk列表信息 |
| | | |
| | | initSoData() |
| | | |
| | | initDictionary() // 初始化字典 |
| | | |
| | | initChan <- true |
| | | } |
| | | |
| | | var newUpdateMsg = &protomsg.DbChangeMessage{} |
| | | |
| | | func updateData(b []byte){ |
| | | if err :=proto.Unmarshal(b,newUpdateMsg);err !=nil{ |
| | | fmt.Println("dbChangeMsg unmarshal err:",err) |
| | | func updateData(b []byte) { |
| | | if err := proto.Unmarshal(b, newUpdateMsg); err != nil { |
| | | fmt.Println("dbChangeMsg unmarshal err:", err) |
| | | return |
| | | } |
| | | switch newUpdateMsg.Table { |
| | |
| | | initServerInfo() |
| | | case protomsg.TableChanged_T_Camera: |
| | | initCamera() |
| | | case protomsg.TableChanged_T_CameraPolygon://更新摄像机多变形 |
| | | case protomsg.TableChanged_T_CameraPolygon: //更新摄像机多变形 |
| | | initPolygons() |
| | | case protomsg.TableChanged_T_TimeRule://更新时间规则 |
| | | case protomsg.TableChanged_T_TimeRule: //更新时间规则 |
| | | initTimeRules() |
| | | case protomsg.TableChanged_T_CameraTask://更新摄像机规则配置参数 |
| | | case protomsg.TableChanged_T_CameraTask: //更新摄像机规则配置参数 |
| | | initCameraTaskRules() |
| | | case protomsg.TableChanged_T_CameraTaskArgs://更新摄像机规则配置参数 |
| | | case protomsg.TableChanged_T_CameraTaskArgs: //更新摄像机规则配置参数 |
| | | initCameraTaskRules() |
| | | case protomsg.TableChanged_T_Sdk://更新sdk配置 |
| | | case protomsg.TableChanged_T_Sdk: //更新sdk配置 |
| | | initSdks() |
| | | default: |
| | | fmt.Println("unknown operation") |
| | |
| | | func initServerInfo() { |
| | | var api dbapi.SysSetApi |
| | | b, s := api.GetServerInfo() |
| | | if b{ |
| | | cMap.Set(SERVER_KEY,s) |
| | | if b { |
| | | cMap.Set(SERVER_KEY, s) |
| | | } |
| | | } |
| | | |
| | | func initCamera() { |
| | | var api dbapi.CameraApi |
| | | cameras := api.FindAll() |
| | | for _,cam := range cameras { |
| | | cMap.Set(PREFIX_CAMERA + cam.Id,cam) |
| | | for _, cam := range cameras { |
| | | cMap.Set(PREFIX_CAMERA+cam.Id, cam) |
| | | } |
| | | } |
| | | |
| | | func initPolygons(){ |
| | | func initPolygons() { |
| | | var api dbapi.CameraApi |
| | | data := api.FindAllPolygons() |
| | | pMap :=make(map[string][]protomsg.CameraPolygon,0) |
| | | pMap := make(map[string][]protomsg.CameraPolygon, 0) |
| | | for _, item := range data { |
| | | if item.Type != "line" { |
| | | cameraId :=item.CameraId |
| | | if _,ok :=pMap[cameraId];ok{ |
| | | pMap[cameraId] = append(pMap[cameraId],item) |
| | | } else{ |
| | | pMap[cameraId]=[]protomsg.CameraPolygon{item} |
| | | cameraId := item.CameraId |
| | | if _, ok := pMap[cameraId]; ok { |
| | | pMap[cameraId] = append(pMap[cameraId], item) |
| | | } else { |
| | | pMap[cameraId] = []protomsg.CameraPolygon{item} |
| | | } |
| | | } |
| | | } |
| | | for k,v :=range pMap{ |
| | | cMap.Set(PREFIX_POLYGON + k,v) |
| | | for k, v := range pMap { |
| | | cMap.Set(PREFIX_POLYGON+k, v) |
| | | } |
| | | } |
| | | |
| | | func initTimeRules(){ |
| | | func initTimeRules() { |
| | | var api dbapi.CameraApi |
| | | flag, rules := api.FindAllTimeRules() |
| | | if flag { |
| | |
| | | } |
| | | } |
| | | |
| | | func initCameraTaskRules(){ |
| | | 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() |
| | | |
| | | for _, taskArg := range all { |
| | | cMap.Set(PREFIX_RULE+taskArg.CameraId,taskArg.TaskArgs) |
| | | cMap.Set(PREFIX_RULE+taskArg.CameraId, taskArg.TaskArgs) |
| | | } |
| | | } |
| | | |
| | | func initSdks(){ |
| | | func initSdks() { |
| | | var api dbapi.SdkApi |
| | | sdks := api.FindAll("") |
| | | for _,sdk :=range sdks { |
| | | cMap.Set(PREFIX_SDK+sdk.Id,sdk) |
| | | for _, sdk := range sdks { |
| | | cMap.Set(PREFIX_SDK+sdk.Id, sdk) |
| | | } |
| | | } |
| | | |
| | | func GetServerInfo() (con protomsg.LocalConfig,err error) { |
| | | func GetServerInfo() (con protomsg.LocalConfig, err error) { |
| | | config, b := cMap.Get(SERVER_KEY) |
| | | if b { |
| | | return config.(protomsg.LocalConfig),nil |
| | | return config.(protomsg.LocalConfig), nil |
| | | } else { |
| | | return con,errors.New("conf not found") |
| | | return con, errors.New("conf not found") |
| | | } |
| | | } |
| | | |
| | | //通过cameraId获取摄像机信息 |
| | | func GetCameraById(cameraId string) (c protomsg.Camera,err error) { |
| | | func GetCameraById(cameraId string) (c protomsg.Camera, err error) { |
| | | cam, b := cMap.Get(PREFIX_CAMERA + cameraId) |
| | | if b { |
| | | return cam.(protomsg.Camera),nil |
| | | return cam.(protomsg.Camera), nil |
| | | } else { |
| | | return c,errors.New("camera not found") |
| | | return c, errors.New("camera not found") |
| | | } |
| | | } |
| | | |
| | | func GetPolygonsByCameraId(cameraId string) []protomsg.CameraPolygon{ |
| | | func GetPolygonsByCameraId(cameraId string) []protomsg.CameraPolygon { |
| | | obj, b := cMap.Get(PREFIX_POLYGON + cameraId) |
| | | if b { |
| | | return obj.([]protomsg.CameraPolygon) |
| | |
| | | } |
| | | |
| | | //从缓存中获取时间规则 |
| | | func GetTimeRuleById(id string) (exist bool,rule protomsg.CameraTimerule){ |
| | | func GetTimeRuleById(id string) (exist bool, rule protomsg.CameraTimerule) { |
| | | obj, b := cMap.Get(PREFIX_TIME + id) |
| | | if b { |
| | | return true,obj.(protomsg.CameraTimerule) |
| | | return true, obj.(protomsg.CameraTimerule) |
| | | } else { |
| | | return false,rule |
| | | return false, rule |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | func GetSdkById(sdkId string) (sdk protomsg.Sdk,err error){ |
| | | obj,b :=cMap.Get(PREFIX_SDK + sdkId) |
| | | func GetSdkById(sdkId string) (sdk protomsg.Sdk, err error) { |
| | | obj, b := cMap.Get(PREFIX_SDK + sdkId) |
| | | if b { |
| | | return obj.(protomsg.Sdk),nil |
| | | return obj.(protomsg.Sdk), nil |
| | | } else { |
| | | return sdk,errors.New("sdk not found") |
| | | 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 |
| | | soinfos := api.FindAll() |
| | | logger.Debug("=====================注册表信息:") |
| | | for _,soinfo :=range soinfos { |
| | | for _, soinfo := range soinfos { |
| | | logger.Debug(soinfo) |
| | | cMap.Set(PREFIX_SO+soinfo.SdkId,soinfo) |
| | | cMap.Set(PREFIX_SO+soinfo.SdkId, soinfo) |
| | | } |
| | | } |
| | | |
| | | func GetSoInfoById(sdkId string) (sdk protomsg.SoInfo,err error){ |
| | | obj,b :=cMap.Get(PREFIX_SO + sdkId) |
| | | func GetSoInfoById(sdkId string) (sdk protomsg.SoInfo, err error) { |
| | | obj, b := cMap.Get(PREFIX_SO + sdkId) |
| | | if b { |
| | | return obj.(protomsg.SoInfo),nil |
| | | return obj.(protomsg.SoInfo), nil |
| | | } else { |
| | | return sdk,errors.New("sdk not found") |
| | | 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) |
| | | //logger.Info("整理后的数据:",faces) |
| | | if faces != nil { |
| | | var imgMaxUrl string = "" |
| | | var picTime string = "" |
| | | for _, face := range faces { |
| | | // 上传大图 |
| | | // 解压缩并上传图片 |
| | | bdata, err := util.UnCompress(msg.Data) |
| | | if err != nil { |
| | | 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, ""}) |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | // 先传小图,再传大图,防止脸上有线 |
| | | bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height)) |
| | | resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String()) |
| | | if err != nil { |
| | | logger.Error("上传小图出错") |
| | | } |
| | | // 上传大图 |
| | | if imgMaxUrl == "" { |
| | | bigPhotoUrl := make(map[string]interface{}) |
| | | bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.Result), weedfsUrl) |
| | | logger.Debug("========大图路径:", bigPhotoUrl) |
| | | 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) |
| | | var target = new(Target) |
| | | target.TargetId = face.Id |
| | | target.TargetScore = face.Score |
| | | target.TargetLocation = Points{TopLeft: Point{face.Location.X, face.Location.Y}, BottomRight: Point{face.Location.X + face.Location.Width, face.Location.Y + face.Location.Height}} |
| | | //logger.Info("人脸的id:",strconv.FormatUint(face.Id, 10)) |
| | | var targetInfos []Target |
| | | targetInfos = append(targetInfos, *target) |
| | | pervideo := PerVideoPicture{ |
| | | face.Uuid, |
| | | msg.Cid, |
| | | msg.Push.Cam.Addr, |
| | | msg.Push.Cam.Name, |
| | | picTime, |
| | | imgMaxUrl, |
| | | msg.Tasklab.Taskid, |
| | | msg.Tasklab.Taskname, |
| | | "人脸", |
| | | 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, |
| | | base64.StdEncoding.EncodeToString(face.Feature), |
| | | []string{resp["fileUrl"].(string)}, |
| | | "", |
| | | msg.Push.ServerId, |
| | | msg.Push.ServerName, |
| | | msg.Push.LocalIp, |
| | | "", |
| | | face.Score, |
| | | 1, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | face.Liker, |
| | | targetInfos, |
| | | "", |
| | | []*LinkInfo{}, |
| | | } |
| | | requstbody, err := json.Marshal(pervideo) |
| | | 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 = "" |
| | | var picTime string = "" |
| | | for _, face := range faces { |
| | | // 上传大图 |
| | | // 解压缩并上传图片 |
| | | bdata, err := util.UnCompress(msg.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | alarmRules := []AlarmRule{} |
| | | for _, faceResult := range face.rules { |
| | | alarm := ChangeToString(faceResult.DefenceState, faceResult.AlarmLevel) |
| | | alarmRules = append(alarmRules, AlarmRule{faceResult.RuleGroupId, alarm, faceResult.RuleText, faceResult.DefenceState, ""}) |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | // 先传小图,再传大图,防止脸上有线 |
| | | bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height)) |
| | | resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String()) |
| | | if err != nil { |
| | | logger.Error("上传小图出错") |
| | | } |
| | | // 上传大图 |
| | | if imgMaxUrl == "" { |
| | | bigPhotoUrl := make(map[string]interface{}) |
| | | bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.Result), weedfsUrl) |
| | | logger.Debug("========大图路径:", bigPhotoUrl) |
| | | imgMaxUrl = bigPhotoUrl["fileUrl"].(string) |
| | | picTime = i.Timestamp |
| | | } |
| | | lable,lableAttach := Feature2Jsonstr(*face) |
| | | var target = new(Target) |
| | | target.TargetId = face.Id |
| | | target.TargetScore = face.Score |
| | | target.TargetLocation = Points{TopLeft: Point{face.Location.X, face.Location.Y}, BottomRight: Point{face.Location.X + face.Location.Width, face.Location.Y + face.Location.Height}} |
| | | //logger.Info("人脸的id:",strconv.FormatUint(face.Id, 10)) |
| | | var targetInfos []Target |
| | | targetInfos = append(targetInfos, *target) |
| | | pervideo := PerVideoPicture{ |
| | | face.Uuid, |
| | | msg.Cid, |
| | | msg.Push.Cam.Addr, |
| | | msg.Push.Cam.Name, |
| | | picTime, |
| | | imgMaxUrl, |
| | | msg.Tasklab.Taskid, |
| | | msg.Tasklab.Taskname, |
| | | "人脸", |
| | | time.Now().Format("2006-01-02 15:04:05"), |
| | | alarmRules, |
| | | time.Now().Format("2006-01-02 15:04:05"), // 只检测,没有比对时间 |
| | | lable, |
| | | lableAttach, |
| | | base64.StdEncoding.EncodeToString(face.Feature), |
| | | []string{resp["fileUrl"].(string)}, |
| | | "", |
| | | msg.Push.ServerId, |
| | | msg.Push.ServerName, |
| | | msg.Push.LocalIp, |
| | | "", |
| | | face.Score, |
| | | 1, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | face.Liker, |
| | | targetInfos, |
| | | "", |
| | | []*LinkInfo{}, |
| | | } |
| | | requstbody, err := json.Marshal(pervideo) |
| | | |
| | | if err != nil { |
| | | logger.Info("json parse error ", err) |
| | | return |
| | | } |
| | | resp1, err1 := EsReq("POST", videoPersonUrl, requstbody) |
| | | if err1 != nil { |
| | | logger.Error("上传ES出错!---", err1) |
| | | } else { |
| | | logger.Info("插入es返回的信息(人脸):", resp1) |
| | | // 发出录像信号 |
| | | ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: face.Uuid, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 1}) |
| | | if err != nil { |
| | | logger.Info("json parse error ", err) |
| | | return |
| | | } |
| | | resp1, err1 := EsReq("POST", videoPersonUrl, requstbody) |
| | | if err1 != nil { |
| | | logger.Error("上传ES出错!---", err1) |
| | | } else { |
| | | logger.Info("插入es返回的信息(人脸):", resp1) |
| | | // 发出录像信号 |
| | | ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: face.Uuid, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 1}) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | // 归置人脸 |
| | | 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) |
| | | } |
| | | return faces |
| | | } else { |
| | | return nil |
| | | func PutFace(objs []*ObjAndRules, resutls []structure.Result) []*ObjAndRules { |
| | | for _, faceResult := range resutls { |
| | | objs = hebingFace(objs, faceResult) |
| | | } |
| | | 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数据 |
| | |
| | | } |
| | | } |
| | | if flag { |
| | | logger.Info("往ES插yolo数据") |
| | | var sdkNames string = "" |
| | | alarmRules := []AlarmRule{} |
| | | var targetInfos []Target |
| | | url := []string{} |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | if yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10" { |
| | | // 拼出sdkname |
| | | //logger.Info("应该进来才对的") |
| | | sdkNames = sdkNames + yoloResult.SdkName |
| | | alarm := ChangeToString(yoloResult.DefenceState, yoloResult.AlarmLevel) |
| | | linkInfo := "" |
| | | if yoloResult.IsLink { |
| | | linkInfo = "联动任务" |
| | | } |
| | | alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState, linkInfo}) |
| | | logger.Info("打印任务名称:",) |
| | | // 上传缓存数据的图片拿到url |
| | | if yoloResult.Others.CacheData != nil { |
| | | //InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg)) |
| | | // 把缓存的数据上传后得到地址存进去 |
| | | // 解压缩并上传图片 |
| | | msgs := yoloResult.Others.CacheData |
| | | for _, msg1 := range msgs { |
| | | bdata, err := util.UnCompress(msg1.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | resp1, err1 := util.DrawPolygonOnImageForYolo(msg1.Cid, i, msg1.RuleResult["yolo"].([]structure.Result), weedfsUrl) |
| | | if err1 != nil { |
| | | logger.Error("缓存数据画框或上传图片服务器出错", err) |
| | | } else { |
| | | logger.Info("上传的图片信息:", resp1) |
| | | } |
| | | if resp1["fileUrl"] != nil { |
| | | url = append(url, resp1["fileUrl"].(string)) |
| | | } |
| | | logger.Info("往ES插yolo数据") |
| | | var sdkNames string = "" |
| | | alarmRules := []AlarmRule{} |
| | | var targetInfos []Target |
| | | url := []string{} |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | if yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10" { |
| | | // 拼出sdkname |
| | | //logger.Info("应该进来才对的") |
| | | sdkNames = sdkNames + yoloResult.SdkName |
| | | alarm := ChangeToString(yoloResult.DefenceState, yoloResult.AlarmLevel) |
| | | linkInfo := "" |
| | | if yoloResult.IsLink { |
| | | linkInfo = "联动任务" |
| | | } |
| | | alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState, linkInfo}) |
| | | logger.Info("打印任务名称:", ) |
| | | // 上传缓存数据的图片拿到url |
| | | if yoloResult.Others.CacheData != nil { |
| | | //InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg)) |
| | | // 把缓存的数据上传后得到地址存进去 |
| | | // 解压缩并上传图片 |
| | | msgs := yoloResult.Others.CacheData |
| | | for _, msg1 := range msgs { |
| | | bdata, err := util.UnCompress(msg1.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | } |
| | | // 装配目标信息数据 |
| | | for _, target := range yoloResult.AlarmObj { |
| | | // 去重添加 |
| | | var flag = true |
| | | for _, selectTarget := range targetInfos { |
| | | if target.Id == selectTarget.TargetId { |
| | | flag = false |
| | | break |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | resp1, err1 := util.DrawPolygonOnImageForYolo(msg1.Cid, i, msg1.RuleResult["yolo"].([]structure.Result), weedfsUrl) |
| | | if err1 != nil { |
| | | logger.Error("缓存数据画框或上传图片服务器出错", err) |
| | | } else { |
| | | logger.Info("上传的图片信息:", resp1) |
| | | } |
| | | if flag { |
| | | var target1 = new(Target) |
| | | target1.TargetId = target.Id |
| | | 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) |
| | | if resp1["fileUrl"] != nil { |
| | | url = append(url, resp1["fileUrl"].(string)) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 联动图像的处理 |
| | | linkTagInfos := []*LinkInfo{} |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | if (yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10") && yoloResult.Others.LinkCache != nil && len(yoloResult.Others.LinkCache) > 1 { |
| | | for _, msg2 := range yoloResult.Others.LinkCache { |
| | | // 把msg2的数据装配成一个PerVideoPicture结构体 |
| | | if msg2.Cid != msg.Cid { |
| | | linkTagInfos = append(linkTagInfos, msg2PersonVideo(msg2)) |
| | | // 装配目标信息数据 |
| | | for _, target := range yoloResult.AlarmObj { |
| | | // 去重添加 |
| | | var flag = true |
| | | for _, selectTarget := range targetInfos { |
| | | if target.Id == selectTarget.TargetId { |
| | | flag = false |
| | | break |
| | | } |
| | | } |
| | | } |
| | | } |
| | | linkTag := "" |
| | | if len(linkTagInfos) > 0 { |
| | | linkTag = "联动任务" |
| | | } |
| | | isAlarm := 0 |
| | | resp := make(map[string]interface{}) |
| | | // 解压缩并上传图片 |
| | | bdata, err := util.UnCompress(msg.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | if len(alarmRules) > 0 { |
| | | isAlarm = 1 |
| | | //resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String()) |
| | | resp, err = util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["yolo"].([]structure.Result), weedfsUrl) |
| | | if err != nil { |
| | | logger.Error("画框或上传图片服务器出错", err) |
| | | return |
| | | } else { |
| | | logger.Info("上传的图片信息:", resp) |
| | | } |
| | | } else { |
| | | isAlarm = 0 |
| | | // 不是报警数据不存 |
| | | return |
| | | } |
| | | if resp["fileUrl"] != nil { |
| | | url = append(url, resp["fileUrl"].(string)) |
| | | //esDataId := uuid.NewV4().String() |
| | | peraction := Personaction{ |
| | | msg.Push.PushId, |
| | | msg.Cid, |
| | | msg.Push.Cam.Name, |
| | | msg.Push.Cam.Addr, |
| | | msg.Tasklab.Taskid, |
| | | msg.Tasklab.Taskname, |
| | | sdkNames, |
| | | time.Now().Format("2006-01-02 15:04:05"), |
| | | alarmRules, |
| | | msg.Push.ServerId, |
| | | msg.Push.ServerName, |
| | | msg.Push.LocalIp, |
| | | "", |
| | | url, |
| | | i.Timestamp, |
| | | "", |
| | | isAlarm, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | targetInfos, |
| | | linkTag, |
| | | linkTagInfos, |
| | | } |
| | | requstbody, err := json.Marshal(peraction) |
| | | |
| | | if len(linkTagInfos)>0 { |
| | | logger.Info("联动任务1111") |
| | | } |
| | | if err != nil { |
| | | logger.Info("json parse error ", err) |
| | | return |
| | | } |
| | | resp1, err2 := EsReq("POST", personAction, requstbody) |
| | | if err2 != nil { |
| | | logger.Error("往ES插入数据失败", err) |
| | | } else { |
| | | logger.Debug("插入es返回的数据信息是(yolo):", resp1) |
| | | // 发出录像信号 |
| | | ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 2}) |
| | | for index,link := range linkTagInfos { |
| | | logger.Info("联动任务的录像信号:",index) |
| | | ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: link.CameraId, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{strconv.Itoa(index)}, Type: 2}) |
| | | if flag { |
| | | var target1 = new(Target) |
| | | target1.TargetId = target.Id |
| | | 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) |
| | | } |
| | | logger.Warn("__________________________________________往ES插入yolo数据成功") |
| | | //os.Exit(1) |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | logger.Debug("timeLabel条件都不符合!") |
| | | // 联动图像的处理 |
| | | linkTagInfos := []*LinkInfo{} |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | if (yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10") && yoloResult.Others.LinkCache != nil && len(yoloResult.Others.LinkCache) > 1 { |
| | | for _, msg2 := range yoloResult.Others.LinkCache { |
| | | // 把msg2的数据装配成一个PerVideoPicture结构体 |
| | | if msg2.Cid != msg.Cid { |
| | | linkTagInfos = append(linkTagInfos, msg2PersonVideo(msg2)) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | linkTag := "" |
| | | if len(linkTagInfos) > 0 { |
| | | linkTag = "联动任务" |
| | | } |
| | | isAlarm := 0 |
| | | resp := make(map[string]interface{}) |
| | | // 解压缩并上传图片 |
| | | bdata, err := util.UnCompress(msg.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | if len(alarmRules) > 0 { |
| | | isAlarm = 1 |
| | | //resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String()) |
| | | resp, err = util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["yolo"].([]structure.Result), weedfsUrl) |
| | | if err != nil { |
| | | logger.Error("画框或上传图片服务器出错", err) |
| | | return |
| | | } else { |
| | | logger.Info("上传的图片信息:", resp) |
| | | } |
| | | } else { |
| | | isAlarm = 0 |
| | | // 不是报警数据不存 |
| | | return |
| | | } |
| | | if resp["fileUrl"] != nil { |
| | | url = append(url, resp["fileUrl"].(string)) |
| | | //esDataId := uuid.NewV4().String() |
| | | peraction := Personaction{ |
| | | msg.Push.PushId, |
| | | msg.Cid, |
| | | msg.Push.Cam.Name, |
| | | msg.Push.Cam.Addr, |
| | | msg.Tasklab.Taskid, |
| | | msg.Tasklab.Taskname, |
| | | sdkNames, |
| | | time.Now().Format("2006-01-02 15:04:05"), |
| | | alarmRules, |
| | | msg.Push.ServerId, |
| | | msg.Push.ServerName, |
| | | msg.Push.LocalIp, |
| | | "", |
| | | url, |
| | | i.Timestamp, |
| | | "", |
| | | isAlarm, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | targetInfos, |
| | | linkTag, |
| | | linkTagInfos, |
| | | } |
| | | requstbody, err := json.Marshal(peraction) |
| | | |
| | | if len(linkTagInfos) > 0 { |
| | | logger.Info("联动任务1111") |
| | | } |
| | | if err != nil { |
| | | logger.Info("json parse error ", err) |
| | | return |
| | | } |
| | | resp1, err2 := EsReq("POST", personAction, requstbody) |
| | | if err2 != nil { |
| | | logger.Error("往ES插入数据失败", err) |
| | | } else { |
| | | logger.Debug("插入es返回的数据信息是(yolo):", resp1) |
| | | // 发出录像信号 |
| | | ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 2}) |
| | | for index, link := range linkTagInfos { |
| | | logger.Info("联动任务的录像信号:", index) |
| | | ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: link.CameraId, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{strconv.Itoa(index)}, Type: 2}) |
| | | } |
| | | logger.Warn("__________________________________________往ES插入yolo数据成功") |
| | | //os.Exit(1) |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | logger.Debug("timeLabel条件都不符合!") |
| | | } |
| | | } |
| | | |
| | |
| | | func InsertTarget(msg structure.ResultMsg) { |
| | | if msg.RuleResult["target"] != nil && len(msg.RuleResult["target"].([]structure.Result)) > 0 { |
| | | // 先判断一下数据带的规则标签是否有可以插入的 |
| | | logger.Info("插入定时目标信息:",len(msg.RuleResult["target"].([]structure.Result))) |
| | | logger.Info("插入定时目标信息:", len(msg.RuleResult["target"].([]structure.Result))) |
| | | for _, yoloResult := range msg.RuleResult["target"].([]structure.Result) { |
| | | // 装载目标信息` |
| | | // 如果有首次报警的则本帧数据可以插入 |
| | | insertFlag := false |
| | | alarmNum := 0 |
| | | for _,obj := range yoloResult.AlarmObj { |
| | | for _, obj := range yoloResult.AlarmObj { |
| | | if obj.TimeLable == "10" { |
| | | insertFlag = true |
| | | alarmNum++ |
| | | } |
| | | } |
| | | if insertFlag { |
| | | logger.Info("报警目标个数:",alarmNum) |
| | | logger.Info("报警目标个数:", alarmNum) |
| | | //var target = new(Target) |
| | | //target.TargetId = strconv.FormatUint(tar.Id, 10) |
| | | //target.TargetScore = tar.Score |
| | |
| | | // 把缓存的数据上传后得到地址存进去 |
| | | // 解压缩并上传图片 |
| | | url1 := uploadImg(yoloResult.AlarmObj[0].CacheData) |
| | | url = append(url,url1) |
| | | url = append(url, url1) |
| | | // 添加报警规则组 |
| | | sdkNames := "" |
| | | alarmRules := []AlarmRule{} |
| | |
| | | } |
| | | requstbody, err := json.Marshal(peraction) |
| | | |
| | | if len(linkTagInfos)>0 { |
| | | if len(linkTagInfos) > 0 { |
| | | logger.Info("联动任务1111") |
| | | } |
| | | if err != nil { |
| | |
| | | logger.Debug("插入es返回的数据信息是(target):", resp1) |
| | | // 发出录像信号 |
| | | ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 2}) |
| | | for index,link := range linkTagInfos { |
| | | logger.Info("联动任务的录像信号:",index) |
| | | for index, link := range linkTagInfos { |
| | | logger.Info("联动任务的录像信号:", index) |
| | | ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: link.CameraId, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{strconv.Itoa(index)}, Type: 2}) |
| | | } |
| | | logger.Warn("__________________________________________往ES插入target数据成功") |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 获取本机ip |
| | | func GetLocalIP() (ipv4 string, err error) { |
| | | var ( |
| | |
| | | return alarm |
| | | } |
| | | |
| | | func uploadImg(msg structure.ResultMsg) string{ |
| | | func uploadImg(msg structure.ResultMsg) string { |
| | | bdata, err := util.UnCompress(msg.Data) |
| | | if err != nil { |
| | | panic("解压缩图片时出现错误") |
| | |
| | | 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 |