From 993dc81c942d6b1315684cda034c8859a6f4d02b Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期三, 06 十一月 2019 11:15:40 +0800 Subject: [PATCH] --- --- insertdata/insertDataToEs.go | 230 ++++++++++++++++++++++++++++++--------------------------- 1 files changed, 120 insertions(+), 110 deletions(-) diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go index 12aa46a..a77c422 100644 --- a/insertdata/insertDataToEs.go +++ b/insertdata/insertDataToEs.go @@ -2,12 +2,12 @@ import ( "basic.com/valib/logger.git" - "ruleprocess/structure" "encoding/base64" "encoding/json" "errors" "net" "ruleprocess/cache" + "ruleprocess/structure" "strconv" "time" @@ -37,39 +37,55 @@ // 浜鸿劯鐨勬暟鎹粨鏋� type PerVideoPicture struct { - Id string `json:"id"` - CameraId string `json:"cameraId"` - CameraAddr string `json:"cameraAddr"` - PicDate string `json:"picDate"` - PicMaxUrl string `json:"picMaxUrl"` - TaskId string `json:"taskId"` - TaskName string `json:"taskName"` - SdkName string `json:"sdkName"` - 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"` - FaceFeature string `json:"faceFeature"` - PicSmUrl []string `json:"picSmUrl"` - VideoUrl string `json:"videoUrl"` - AnalyServerId string `json:"analyServerId"` - AnalyServerName string `json:"analyServerName"` - AnalyServerIp string `json:"analyServerIp"` - ClusterId string `json:"clusterId"` - LinkId string `json:"linkId"` - DetectScore float64 `json:"detectScore"` - IsAlarm int `json:"isAlarm"` - IsAckAlarm int `json:"isAckAlarm"` - IsCollect int `json:"isCollect"` - IsDelete int `json:"isDelete"` + Id string `json:"id"` + CameraId string `json:"cameraId"` + CameraAddr string `json:"cameraAddr"` + PicDate string `json:"picDate"` + PicMaxUrl string `json:"picMaxUrl"` + TaskId string `json:"taskId"` + TaskName string `json:"taskName"` + SdkName string `json:"sdkName"` + 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"` + FaceFeature string `json:"faceFeature"` + PicSmUrl []string `json:"picSmUrl"` + VideoUrl string `json:"videoUrl"` + AnalyServerId string `json:"analyServerId"` + AnalyServerName string `json:"analyServerName"` + AnalyServerIp string `json:"analyServerIp"` + ClusterId string `json:"clusterId"` + LinkId string `json:"linkId"` + DetectScore float64 `json:"detectScore"` + IsAlarm int `json:"isAlarm"` + IsAckAlarm int `json:"isAckAlarm"` + IsCollect int `json:"isCollect"` + IsDelete int `json:"isDelete"` BaseInfo []*structure.BaseInfo `json:"baseInfo"` + TargetInfo Target } +type Target struct { + TargetId string `json:"targetId"` + TargetScore float64 `json:"targetScore"` + TargetLocation Points +} + +type Points struct { + TopLeft Point `json:"topLeft"` + BottomRight Point `json:"bottomRight"` +} + +type Point struct { + Lat float64 `json:"lat"` + Lon float64 `json:"lon"` +} // yolo琛屼负鐨勬暟鎹粨鏋� type Personaction struct { Id string `json:"id"` @@ -93,6 +109,7 @@ IsAckAlarm int `json:"isAckAlarm"` IsCollect int `json:"isCollect"` IsDelete int `json:"isDelete"` + TargetInfo []Target } type AlarmRule struct { @@ -100,8 +117,8 @@ AlarmLevel string `json:"alarmLevel"` RuleText string `json:"ruleText"` DefenceState bool `json:"defenceState"` - IsLink bool `json:"isLink"` - LinkInfo string `json:"linkInfo"` + IsLink bool `json:"isLink"` + LinkInfo string `json:"linkInfo"` } // 涓�涓猣ace瀵瑰涓鍒欑粍鐨勫綊缃汉鑴哥殑缁撴瀯浣� @@ -137,31 +154,18 @@ func InsertToEs(msg structure.ResultMsg) { defer func() { if err := recover(); err != nil { - logger.Error("es妯″潡鍎跨殑寮傚父鎹曡幏锛�",err) + logger.Error("es妯″潡鍎跨殑寮傚父鎹曡幏锛�", err) } }() localConfig1, err := cache.GetServerInfo() if err != nil { panic("閰嶇疆鏂囦欢涓嶅悎娉�") } - weedfsUrl = "http://"+localConfig1.WebPicIp+":"+strconv.Itoa(int(localConfig1.WebPicPort))+"/submit" - videoPersonUrl = "http://"+localConfig1.AlarmIp+":"+strconv.Itoa(int(localConfig1.AlarmPort))+"/"+EsInfo.EsIndex.VideoPersons.IndexName+"/"+EsInfo.EsIndex.VideoPersons.IndexType - personAction = "http://"+localConfig1.AlarmIp+":"+strconv.Itoa(int(localConfig1.AlarmPort))+"/"+EsInfo.EsIndex.Personaction.IndexName+"/"+EsInfo.EsIndex.Personaction.IndexType + weedfsUrl = "http://" + localConfig1.WebPicIp + ":" + strconv.Itoa(int(localConfig1.WebPicPort)) + "/submit" + videoPersonUrl = "http://" + localConfig1.AlarmIp + ":" + strconv.Itoa(int(localConfig1.AlarmPort)) + "/" + EsInfo.EsIndex.VideoPersons.IndexName + "/" + EsInfo.EsIndex.VideoPersons.IndexType + personAction = "http://" + localConfig1.AlarmIp + ":" + strconv.Itoa(int(localConfig1.AlarmPort)) + "/" + EsInfo.EsIndex.Personaction.IndexName + "/" + EsInfo.EsIndex.Personaction.IndexType InsertFace(msg, "") - // 濡傛灉鏍囩涓惈鏈夋寔缁椂闂撮娆℃姤璀︾殑timeLabel鐨勮瘽鍒欎笉闇�瑕佽繃浜轰綋杩借釜锛屼笉鐒跺氨娌$殑鎻掑叆浜� - fk := ruleserver.TrackOrNot(msg.RuleResult) - if fk { - InsertYolo(msg, "") - //if msg.Cid == "61de081a-7ed9-4970-8432-41d642c35456" { - // logger.Warn("鎹曟崏188鎽勫儚鏈虹殑鎸佺画鏃堕棿浠诲姟.....") - // os.Exit(1) - //} - } else { - flag := ruleserver.BodyIsSame(msg.SdkMessage) - if !flag { - InsertYolo(msg, "") - } - } + InsertYolo(msg, "") } // 寰�es涓彃鍏ヤ汉鑴告暟鎹� @@ -169,12 +173,12 @@ if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.FaceResult)) > 0 { logger.Info("寰�ES鎻掍汉鑴告暟鎹�") faces := []*FaceAndRules{} - faces = PutFace(faces,msg) + faces = PutFace(faces, msg) //logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces) if faces != nil { var imgMaxUrl string = "" var picTime string = "" - for _,face := range faces { + for _, face := range faces { // 涓婁紶澶у浘 // 瑙e帇缂╁苟涓婁紶鍥剧墖 bdata, err := util.UnCompress(msg.Data) @@ -182,14 +186,21 @@ panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒") } alarmRules := []AlarmRule{} - logger.Warn("浜鸿劯id涓猴細",face.Id,"浜鸿劯鐨勮鍒欓暱搴︿负锛�",len(face.rules)) + logger.Warn("浜鸿劯id涓猴細", face.Id, "浜鸿劯鐨勮鍒欓暱搴︿负锛�", len(face.rules)) //os.Exit(1) - for _,faceResult := range face.rules { + for _, faceResult := range face.rules { alarm := ChangeToString(faceResult.DefenceState, faceResult.AlarmLevel) - alarmRules = append(alarmRules, AlarmRule{faceResult.RuleGroupId, alarm, faceResult.RuleText, faceResult.DefenceState,faceResult.IsLink,""}) + alarmRules = append(alarmRules, AlarmRule{faceResult.RuleGroupId, alarm, faceResult.RuleText, faceResult.DefenceState, faceResult.IsLink, ""}) } 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.FaceResult), weedfsUrl) @@ -197,23 +208,6 @@ imgMaxUrl = bigPhotoUrl["fileUrl"].(string) picTime = i.Timestamp } - // 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛� - localConfig, err := cache.GetServerInfo() - if err != nil { - logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�") - } - serverIp, err := GetLocalIP() - // 鏌ヨcameraName - camera, err := cache.GetCameraById(msg.Cid) - if err != nil { - logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�") - } - 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("涓婁紶灏忓浘鍑洪敊") - } - //logger.Info("================灏忓浘鍦板潃:", resp["fileUrl"].(string)) sex := "" logger.Info(sex) if face.ThftRes.Gender == 1 { @@ -229,12 +223,16 @@ if linkId != "" { linksId = linkId } + var target = new(Target) + target.TargetId = strconv.FormatUint(face.Id, 10) + 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("浜鸿劯鐨刬d:",strconv.FormatUint(face.Id, 10)) - //logger.Info("浜鸿劯鐨勫垎鍊硷細",face.Score) + logger.Info("%%%%%%%%%%%%%%%%%%%%%鐩爣淇℃伅锛�",*target) pervideo := PerVideoPicture{ esDataId, msg.Cid, - camera.Addr, + msg.Push.Cam.Addr, picTime, imgMaxUrl, msg.Tasklab.Taskid, @@ -243,7 +241,7 @@ "", alarmRules, time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿 - sex, //鏆傛敼涓轰汉鑴竔d strconv.FormatUint(face.Id, 10) + sex, //鏆傛敼涓轰汉鑴竔d strconv.FormatUint(face.Id, 10) face.ThftRes.Age, ageDescription, // 鏆傛敼涓哄垎鍊糵mt.Sprintf("%.2f",face.Score) race, @@ -251,10 +249,10 @@ face.ThftRes.Beauty, base64.StdEncoding.EncodeToString(face.Feature), []string{resp["fileUrl"].(string)}, - "鏆傛棤闆嗙兢", - localConfig.ServerId, - localConfig.ServerName, - serverIp, + msg.Push.VideoUrl, + msg.Push.ServerId, + msg.Push.ServerName, + msg.Push.LocalIp, "", linksId, face.Score, @@ -263,6 +261,7 @@ 0, 0, face.Liker, + *target, } requstbody, err := json.Marshal(pervideo) @@ -276,7 +275,7 @@ } else { logger.Info("鎻掑叆es杩斿洖鐨勪俊鎭細", resp1) // 鍙戝嚭褰曞儚淇″彿 - ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, ImgId: i.Id, SdkIds: []string{}, Type: 1}) + ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl:msg.Push.VideoUrl,ImgId: i.Id, SdkIds: []string{}, Type: 1}) } } } @@ -284,7 +283,7 @@ } // 褰掔疆浜鸿劯 -func PutFace(faces []*FaceAndRules,msg structure.ResultMsg)[]*FaceAndRules{ +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) @@ -294,28 +293,28 @@ return nil } } -func hebingFace(faces []*FaceAndRules, faceResult structure.FaceResult) []*FaceAndRules{ +func hebingFace(faces []*FaceAndRules, faceResult structure.FaceResult) []*FaceAndRules { for _, arg := range faceResult.Args { // 鎷垮埌姣忎竴寮犱汉鑴� - logger.Info("褰掔疆浜鸿劯鏃剁浉浼艰�呯殑鏁伴噺锛�",len(arg.Liker)) + logger.Info("褰掔疆浜鸿劯鏃剁浉浼艰�呯殑鏁伴噺锛�", len(arg.Liker)) flag := false for _, face := range faces { - for _,lik := range face.Liker { - logger.Warn("--------鍚堝苟浜鸿劯鏃剁浉浼艰�咃細",lik.PersonId,lik.TableName) + for _, lik := range face.Liker { + logger.Warn("--------鍚堝苟浜鸿劯鏃剁浉浼艰�咃細", lik.PersonId, lik.TableName) } if arg.Id == face.Id { flag = true - face.rules = append(face.rules,faceResult.Result) + face.rules = append(face.rules, faceResult.Result) // 鐩镐技鑰呭幓閲嶅綊骞� - for _,liker := range arg.Liker { + for _, liker := range arg.Liker { flag1 := true - for _,liker1 := range face.Liker { + for _, liker1 := range face.Liker { if liker.PersonId == liker1.PersonId { flag1 = false } } if flag1 { - face.Liker = append(face.Liker,liker) + face.Liker = append(face.Liker, liker) } } //face.Liker = append(face.Liker,arg.Liker...) @@ -343,6 +342,7 @@ logger.Info("寰�ES鎻抷olo鏁版嵁") 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" { @@ -354,7 +354,7 @@ if yoloResult.IsLink { linkInfo = "鑱斿姩浠诲姟" } - alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState,yoloResult.IsLink,linkInfo}) + alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState, yoloResult.IsLink, linkInfo}) // 涓婁紶缂撳瓨鏁版嵁鐨勫浘鐗囨嬁鍒皍rl if yoloResult.Others.CacheData != nil { //InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg)) @@ -377,6 +377,25 @@ if resp1["fileUrl"] != nil { url = append(url, resp1["fileUrl"].(string)) } + } + } + // 瑁呴厤鐩爣淇℃伅鏁版嵁 + for _,target := range yoloResult.Location { + // 鍘婚噸娣诲姞 + logger.Info("瑁呴厤鍓嶇殑鍘熷鏁版嵁鏄細",target) + var flag = true + for _,selectTarget := range targetInfos { + if strconv.FormatUint(target.TargetId, 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}} + targetInfos = append(targetInfos,*target1) } } } @@ -423,18 +442,7 @@ // 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨 return } - // logger.Println("鍥剧墖涓婁紶杩斿洖鍊硷細", resp) - // 鏌ヨ鏈満淇℃伅 - localConfig, err := cache.GetServerInfo() - if err != nil { - logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�") - } - // 鏌ヨcameraName - camera, err := cache.GetCameraById(msg.Cid) - if err != nil { - logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�") - } - serverIp, err := GetLocalIP() + if resp["fileUrl"] != nil { url = append(url, resp["fileUrl"].(string)) esDataId := uuid.NewV4().String() @@ -445,25 +453,26 @@ peraction := Personaction{ esDataId, msg.Cid, - camera.Name, - camera.Addr, + msg.Push.Cam.Name, + msg.Push.Cam.Addr, msg.Tasklab.Taskid, msg.Tasklab.Taskname, sdkNames, "", alarmRules, - localConfig.ServerId, - localConfig.ServerName, - serverIp, + msg.Push.ServerId, + msg.Push.ServerName, + msg.Push.LocalIp, "", url, i.Timestamp, linksId, - "", + msg.Push.VideoUrl, isAlarm, 0, 0, 0, + targetInfos, } requstbody, err := json.Marshal(peraction) @@ -478,7 +487,8 @@ } else { logger.Debug("鎻掑叆es杩斿洖鐨勬暟鎹俊鎭槸锛�", resp1) // 鍙戝嚭褰曞儚淇″彿 - ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, ImgId: i.Id, SdkIds: []string{}, Type: 2}) + logger.Info("缁欏綍鍍忕殑瑙嗛鍦板潃锛�",msg.Push.VideoUrl) + ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid,VideoUrl:msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{}, Type: 2}) logger.Warn("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛") //os.Exit(1) } -- Gitblit v1.8.0