| | |
| | | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "ruleprocess/structure" |
| | | "encoding/base64" |
| | | "encoding/json" |
| | | "errors" |
| | |
| | | IsAckAlarm int `json:"isAckAlarm"` |
| | | IsCollect int `json:"isCollect"` |
| | | IsDelete int `json:"isDelete"` |
| | | BaseInfo []*ruleserver.BaseInfo `json:"baseInfo"` |
| | | BaseInfo []*structure.BaseInfo `json:"baseInfo"` |
| | | } |
| | | |
| | | // yolo行为的数据结构 |
| | |
| | | |
| | | // 一个face对多个规则组的归置人脸的结构体 |
| | | type FaceAndRules struct { |
| | | ruleserver.Arg |
| | | rules []ruleserver.Result |
| | | structure.Arg |
| | | rules []structure.Result |
| | | } |
| | | |
| | | // 往ES插数据 |
| | |
| | | // // ChangeStatusYolo(msg) |
| | | // //} |
| | | //} |
| | | func InsertToEs(msg ruleserver.ResultMsg) { |
| | | func InsertToEs(msg structure.ResultMsg) { |
| | | defer func() { |
| | | if err := recover(); err != nil { |
| | | logger.Error("es模块儿的异常捕获:",err) |
| | |
| | | } |
| | | |
| | | // 往es中插入人脸数据 |
| | | func InsertFace(msg ruleserver.ResultMsg, linkId string) { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.FaceResult)) > 0 { |
| | | func InsertFace(msg structure.ResultMsg, linkId string) { |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.FaceResult)) > 0 { |
| | | logger.Info("往ES插人脸数据") |
| | | faces := []*FaceAndRules{} |
| | | faces = PutFace(faces,msg) |
| | |
| | | err = proto.Unmarshal(bdata, &i) |
| | | if imgMaxUrl == "" { |
| | | bigPhotoUrl := make(map[string]interface{}) |
| | | bigPhotoUrl, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String()) |
| | | bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.FaceResult), weedfsUrl) |
| | | logger.Debug("========大图路径:", bigPhotoUrl) |
| | | imgMaxUrl = bigPhotoUrl["fileUrl"].(string) |
| | | picTime = i.Timestamp |
| | |
| | | } |
| | | |
| | | // 归置人脸 |
| | | func PutFace(faces []*FaceAndRules,msg ruleserver.ResultMsg)[]*FaceAndRules{ |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.FaceResult)) > 0 { |
| | | for _, faceResult := range msg.RuleResult["face"].([]ruleserver.FaceResult) { |
| | | func PutFace(faces []*FaceAndRules,msg structure.ResultMsg)[]*FaceAndRules{ |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.FaceResult)) > 0 { |
| | | for _, faceResult := range msg.RuleResult["face"].([]structure.FaceResult) { |
| | | faces = hebingFace(faces, faceResult) |
| | | } |
| | | return faces |
| | |
| | | return nil |
| | | } |
| | | } |
| | | func hebingFace(faces []*FaceAndRules, faceResult ruleserver.FaceResult) []*FaceAndRules{ |
| | | func hebingFace(faces []*FaceAndRules, faceResult structure.FaceResult) []*FaceAndRules{ |
| | | for _, arg := range faceResult.Args { |
| | | // 拿到每一张人脸 |
| | | logger.Info("归置人脸时相似者的数量:",len(arg.Liker)) |
| | |
| | | } |
| | | } |
| | | if !flag { |
| | | faces = append(faces, &FaceAndRules{arg, []ruleserver.Result{faceResult.Result}}) |
| | | faces = append(faces, &FaceAndRules{arg, []structure.Result{faceResult.Result}}) |
| | | } |
| | | } |
| | | return faces |
| | | } |
| | | |
| | | // 往es中插入yolo数据 |
| | | func InsertYolo(msg ruleserver.ResultMsg, linkId string) { |
| | | if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]ruleserver.Result)) > 0 { |
| | | func InsertYolo(msg structure.ResultMsg, linkId string) { |
| | | if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]structure.Result)) > 0 { |
| | | // 先判断一下数据带的规则标签是否有可以插入的 |
| | | flag := false |
| | | for _, res := range msg.RuleResult["yolo"].([]ruleserver.Result) { |
| | | for _, res := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | //logger.Info("定时器打的数字标签:",res.Others.TimeLabel) |
| | | if res.Others.TimeLabel == "01" || res.Others.TimeLabel == "10" { |
| | | flag = true |
| | |
| | | var sdkNames string = "" |
| | | alarmRules := []AlarmRule{} |
| | | url := []string{} |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) { |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) { |
| | | if yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10" { |
| | | // 拼出sdkname |
| | | //logger.Info("应该进来才对的") |
| | |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | resp1, err1 := util.DrawPolygonOnImage(msg1.Cid, i, msg1.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl) |
| | | resp1, err1 := util.DrawPolygonOnImageForYolo(msg1.Cid, i, msg1.RuleResult["yolo"].([]structure.Result), weedfsUrl) |
| | | if err1 != nil { |
| | | logger.Error("缓存数据画框或上传图片服务器出错", err) |
| | | } else { |
| | |
| | | } |
| | | } |
| | | linkFlag := false |
| | | for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) { |
| | | 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 { |
| | | linkId := uuid.NewV4().String() |
| | | for _, msg2 := range yoloResult.Others.LinkCache { |
| | |
| | | if len(alarmRules) > 0 { |
| | | isAlarm = 1 |
| | | //resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String()) |
| | | resp, err = util.DrawPolygonOnImage(msg.Cid, i, msg.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl) |
| | | resp, err = util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["yolo"].([]structure.Result), weedfsUrl) |
| | | if err != nil { |
| | | logger.Error("画框或上传图片服务器出错", err) |
| | | return |