From 5c5433ce457ce751249e45d0950f8acc7ce27d55 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期四, 24 十月 2019 15:46:41 +0800
Subject: [PATCH] 地址前拼一个tcp
---
insertdata/insertDataToEs.go | 661 +++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 500 insertions(+), 161 deletions(-)
diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index f7ab22a..9704795 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -1,15 +1,16 @@
package insertdata
import (
+ "basic.com/valib/logger.git"
+ "encoding/base64"
"encoding/json"
"errors"
- "fmt"
- "log"
"net"
- "strings"
+ "ruleprocess/cache"
+ "ruleprocess/structure"
+ "strconv"
"time"
- "basic.com/dbapi.git"
"basic.com/pubsub/protomsg.git"
"github.com/golang/protobuf/proto"
"github.com/satori/go.uuid"
@@ -17,53 +18,74 @@
"ruleprocess/util"
)
-var weedfsUrl = "http://192.168.1.182:6333/submit"
+var weedfsUrl, videoPersonUrl, personAction string
+
+type conf struct {
+ PhotoUrl string `yaml:"photoUrl"`
+ VideoPersons string `yaml:"videoPersons"`
+ PersonAction string `yaml:"personAction"`
+ ServerIp string `yaml:"serverIp"`
+ ServerPort string `yaml:"serverPort"`
+ DbTablePersons string `yaml:"dbTablePersons"`
+}
+
+//func InitInsertEs() {
+// weedfsUrl = "http://"+WeedFs.Ip+":"+strconv.Itoa(WeedFs.UploadPort)+"/submit"
+// videoPersonUrl = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.VideoPersons.IndexName+"/"+EsInfo.EsIndex.VideoPersons.IndexType
+// personAction = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.Personaction.IndexName+"/"+EsInfo.EsIndex.Personaction.IndexType
+//}
+
// 浜鸿劯鐨勬暟鎹粨鏋�
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"`
- LikeDate string `json:"likeDate"`
- Sex int32 `json:"sex"`
- Age int32 `json:"age"`
- AgeDescription string `json:"ageDescription"`
- Race int32 `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"`
- IsAlarm string `json:"isAlarm"`
- IsAckAlarm string `json:"isAckAlarm"`
- IsCollect string `json:"isCollect"`
- IsDelete int `json:"isDelete"`
- BaseInfo Base `json:"baseInfo"`
+ 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 Base struct {
- TableId string `json:"tableId"`
- TableName string `json:"tableName"`
- CompareScore float64 `json:"compareScore"`
- PersonId string `json:"personId"`
- PersonName string `json:"personName"`
- PersonPicUrl string `json:"personPicUrl"`
- PhoneNum string `json:"phoneNum"`
- Sex string `json:"sex"`
- IdCard string `json:"idCard"`
- MonitorLevel string `json:"monitorLevel"`
- Content string `json:"content"`
+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"`
@@ -74,120 +96,353 @@
TaskName string `json:"taskName"`
SdkName string `json:"sdkName"`
Content string `json:"content"`
- AlarmRules []AlarmRule `json: "alramRules"`
+ AlarmRules []AlarmRule `json:"alarmRules"`
AnalyServerId string `json:"analyServerId"`
AnalyServerName string `json:"analyServerName"`
AnalyServerIp string `json:"analyServerIp"`
ClusterId string `json:"clusterId"`
PicSmUrl []string `json:"picSmUrl"`
PicDate string `json:"picDate"`
+ LinkId string `json:"linkId"`
VideoUrl string `json:"videoUrl"`
- IsAlarm string `json:"isAlarm"`
- IsAckAlarm string `json:"isAckAlarm"`
- IsCollect string `json:"isCollect"`
+ IsAlarm int `json:"isAlarm"`
+ IsAckAlarm int `json:"isAckAlarm"`
+ IsCollect int `json:"isCollect"`
IsDelete int `json:"isDelete"`
+ TargetInfo []Target
}
type AlarmRule struct {
- GroupId string `json:"groupId"`
- AlarmLevel int32 `json:"alarmLevel"`
- RuleText string `json:"ruleText"`
+ GroupId string `json:"groupId"`
+ AlarmLevel string `json:"alarmLevel"`
+ RuleText string `json:"ruleText"`
+ DefenceState bool `json:"defenceState"`
+ IsLink bool `json:"isLink"`
+ LinkInfo string `json:"linkInfo"`
+}
+
+// 涓�涓猣ace瀵瑰涓鍒欑粍鐨勫綊缃汉鑴哥殑缁撴瀯浣�
+type FaceAndRules struct {
+ structure.Arg
+ rules []structure.Result
}
// 寰�ES鎻掓暟鎹�
-func InsertToEs(msg ruleserver.ResultMsg) {
+//func InsertToEs(msg ruleserver.ResultMsg) {
+// var timeLabel string
+// // 鐩存帴浠庤鍒欑殑鏍囩鏁版嵁閲屾嬁绗﹀悎瑙勫垯鐨勪汉鑴哥粨鏋�
+// if msg.RuleResult["timeLabel"] != nil {
+// timeLabel = msg.RuleResult["timeLabel"].(string)
+// }
+// logger.Debug("鎻掑叆鏁版嵁鍓嶇湅鐪嬫姤璀︽爣蹇椾綅锛�", timeLabel)
+// if timeLabel == "01" { // 鏃犲畾鏃跺櫒鐘舵�佽鎻掑叆鐨勬姤璀︽暟鎹�
+// InsertFace(msg)
+// flag := ruleserver.BodyIsSame(msg.SdkMessage)
+// if !flag {
+// InsertYolo(msg)
+// }
+// }
+// if timeLabel == "10" { // 瀹氭椂鍣ㄧ姸鎬佽鎻掑叆鐨勯甯ф姤璀︽暟鎹�傝繛甯︾潃瀹氭椂鍣ㄥ紑鍚椂鐨勯偅甯�
+// InsertFace(msg)
+// InsertYolo(msg)
+// }
+// //if timeLabel == "12" { // 骞堕潪鎶ヨ鏁版嵁锛屽彧鏄姸鎬佹敼鍙樼殑鏁版嵁
+// // //ChangeStatusFace(msg)
+// // ChangeStatusYolo(msg)
+// //}
+//}
+func InsertToEs(msg structure.ResultMsg) {
+ defer func() {
+ if err := recover(); err != nil {
+ 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
+ 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, "")
+ }
+ }
+}
- // 鐩存帴浠庤鍒欑殑鏍囩鏁版嵁閲屾嬁绗﹀悎瑙勫垯鐨勪汉鑴哥粨鏋�
- if msg.RuleResult["faces"] != nil && len(msg.RuleResult["faces"].([]ruleserver.Arg)) > 0 {
- log.Println("寰�ES鎻掍汉鑴告暟鎹�")
- for _, face := range msg.RuleResult["faces"].([]ruleserver.Arg) {
- // 涓婁紶澶у浘
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata, &i)
- bigPhotoUrl := make(map[string]interface{})
- bigPhotoUrl, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
- fmt.Println(bigPhotoUrl)
- if len(face.Liker) == 0 {
- // 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
- flag, localConfig := dbapi.SysSetApi{}.GetServerInfo()
- if !flag {
- log.Println("鏌ヨ鏈満淇℃伅澶辫触锛�")
- }
- serverIp, err := GetLocalIP()
+// 寰�es涓彃鍏ヤ汉鑴告暟鎹�
+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)
+ //logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces)
+ if faces != nil {
+ var imgMaxUrl string = ""
+ var picTime string = ""
+ for _, face := range faces {
+ // 涓婁紶澶у浘
// 瑙e帇缂╁苟涓婁紶鍥剧墖
bdata, err := util.UnCompress(msg.Data)
if err != nil {
panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
}
+ alarmRules := []AlarmRule{}
+ logger.Warn("浜鸿劯id涓猴細", face.Id, "浜鸿劯鐨勮鍒欓暱搴︿负锛�", len(face.rules))
+ //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, faceResult.IsLink, ""})
+ }
i := protomsg.Image{}
err = proto.Unmarshal(bdata, &i)
- i1 := protomsg.Image{}
- i1 = util.Subimg(i.Data, 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.PostFormBufferData(weedfsUrl, i1, uuid.NewV4().String())
- if err != nil {
- log.Println("涓婁紶灏忓浘鍑洪敊")
+ if imgMaxUrl == "" {
+ bigPhotoUrl := make(map[string]interface{})
+ bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.FaceResult), weedfsUrl)
+ logger.Debug("========澶у浘璺緞锛�", bigPhotoUrl)
+ 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 {
+ sex = "鐢�"
+ } else {
+ sex = "濂�"
+ }
+ race := getRaceString(face.ThftRes.Race)
+ ageDescription := getDescription(face.ThftRes.Age)
+ logger.Info(ageDescription)
+ esDataId := uuid.NewV4().String()
+ linksId := ""
+ 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("%%%%%%%%%%%%%%%%%%%%%鐩爣淇℃伅锛�",*target)
pervideo := PerVideoPicture{
- uuid.NewV4().String(),
+ esDataId,
msg.Cid,
- msg.Caddr,
- time.Now().Format("2006-01-02 15:04:05"),
- bigPhotoUrl["fileUrl"].(string),
+ camera.Addr,
+ picTime,
+ imgMaxUrl,
msg.Tasklab.Taskid,
msg.Tasklab.Taskname,
- face.SdkName,
+ "浜鸿劯",
"",
- "", // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
- face.ThftRes.Gender,
+ alarmRules,
+ time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
+ sex, //鏆傛敼涓轰汉鑴竔d strconv.FormatUint(face.Id, 10)
face.ThftRes.Age,
- "",
- face.ThftRes.Race,
+ ageDescription, // 鏆傛敼涓哄垎鍊糵mt.Sprintf("%.2f",face.Score)
+ race,
face.ThftRes.Smile,
face.ThftRes.Beauty,
- "涓嶆槸姣忎釜浜鸿劯绠楁硶閮芥湁",
- resp["fileUrl"].(string),
+ base64.StdEncoding.EncodeToString(face.Feature),
+ []string{resp["fileUrl"].(string)},
"鏆傛棤闆嗙兢",
localConfig.ServerId,
localConfig.ServerName,
serverIp,
"",
- "",
- "",
- "",
+ linksId,
+ face.Score,
+ 1,
0,
- Base{},
+ 0,
+ 0,
+ face.Liker,
+ *target,
}
requstbody, err := json.Marshal(pervideo)
if err != nil {
- log.Println("json parse error ", err)
+ logger.Info("json parse error ", err)
return
-
}
- err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
- if err != nil {
- log.Println("es can not execute right.")
+ resp1, err1 := EsReq("POST", videoPersonUrl, requstbody)
+ if err1 != nil {
+ logger.Error("涓婁紶ES鍑洪敊锛�---", err1)
+ } 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})
}
}
}
}
- if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]ruleserver.Result)) > 0 {
- log.Println("寰�ES鎻抷olo鏁版嵁")
- var sdkNames string = ""
- alarmRules := []AlarmRule{}
- for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) {
- sdkNames = sdkNames + yoloResult.SdkName
- alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, yoloResult.AlarmLevel, yoloResult.RuleText})
+}
+
+// 褰掔疆浜鸿劯
+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)
}
- isAlarm := ""
- resp := make(map[string]interface{})
- if len(alarmRules) > 0 {
- isAlarm = "1"
+ return faces
+ } else {
+ return nil
+ }
+}
+func hebingFace(faces []*FaceAndRules, faceResult structure.FaceResult) []*FaceAndRules {
+ for _, arg := range faceResult.Args {
+ // 鎷垮埌姣忎竴寮犱汉鑴�
+ logger.Info("褰掔疆浜鸿劯鏃剁浉浼艰�呯殑鏁伴噺锛�", len(arg.Liker))
+ flag := false
+ for _, face := range faces {
+ 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)
+ // 鐩镐技鑰呭幓閲嶅綊骞�
+ for _, liker := range arg.Liker {
+ flag1 := true
+ 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,arg.Liker...)
+ }
+ }
+ if !flag {
+ faces = append(faces, &FaceAndRules{arg, []structure.Result{faceResult.Result}})
+ }
+ }
+ return faces
+}
+
+// 寰�es涓彃鍏olo鏁版嵁
+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"].([]structure.Result) {
+ //logger.Info("瀹氭椂鍣ㄦ墦鐨勬暟瀛楁爣绛撅細",res.Others.TimeLabel)
+ if res.Others.TimeLabel == "01" || res.Others.TimeLabel == "10" {
+ flag = true
+ }
+ }
+ if flag {
+ 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" {
+ // 鎷煎嚭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, yoloResult.IsLink, linkInfo})
+ // 涓婁紶缂撳瓨鏁版嵁鐨勫浘鐗囨嬁鍒皍rl
+ if yoloResult.Others.CacheData != nil {
+ //InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
+ // 鎶婄紦瀛樼殑鏁版嵁涓婁紶鍚庡緱鍒板湴鍧�瀛樿繘鍘�
+ // 瑙e帇缂╁苟涓婁紶鍥剧墖
+ msgs := yoloResult.Others.CacheData
+ for _, msg1 := range msgs {
+ bdata, err := util.UnCompress(msg1.Data)
+ if err != nil {
+ panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+ }
+ 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))
+ }
+ }
+ }
+ // 瑁呴厤鐩爣淇℃伅鏁版嵁
+ 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)
+ }
+ }
+ }
+ }
+ linkFlag := false
+ 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 {
+ logger.Warn("鎻掑叆鑱斿姩鏁版嵁", "姝ゅ抚鏁版嵁鐨刬d涓�", msg2.Cid)
+ InsertYolo(msg2, linkId)
+ linkFlag = true
+ }
+ }
+ }
+ if linkFlag {
+ // 鑱斿姩鏁版嵁涓寘鍚湰甯ф暟鎹紝鎻掑叆鑱斿姩鏁版嵁鍚庡氨涓嶉渶瑕佹彃鍏ユ湰甯ф暟鎹簡
+ logger.Warn("鎴愬姛鎻掑叆涓や釜鑱斿姩鍥剧墖")
+ //os.Exit(1)
+ return
+ }
+ //logger.Info("--------璧板埌杩欏効灏变笉涓�鏍�")
+ isAlarm := 0
+ resp := make(map[string]interface{})
// 瑙e帇缂╁苟涓婁紶鍥剧墖
bdata, err := util.UnCompress(msg.Data)
if err != nil {
@@ -195,57 +450,86 @@
}
i := protomsg.Image{}
err = proto.Unmarshal(bdata, &i)
- resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
- log.Println("宸叉姤璀﹀苟涓婁紶鏀瑰抚鍥剧墖鍒版湇鍔″櫒")
+ 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
+ }
+ // 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()
+ logger.Info("%%%%%%%%%%%%%%%%%yolo鐨則arget淇℃伅锛�",targetInfos)
+ if resp["fileUrl"] != nil {
+ url = append(url, resp["fileUrl"].(string))
+ esDataId := uuid.NewV4().String()
+ linksId := ""
+ if linkId != "" {
+ linksId = linkId
+ }
+ peraction := Personaction{
+ esDataId,
+ msg.Cid,
+ camera.Name,
+ camera.Addr,
+ msg.Tasklab.Taskid,
+ msg.Tasklab.Taskname,
+ sdkNames,
+ "",
+ alarmRules,
+ localConfig.ServerId,
+ localConfig.ServerName,
+ serverIp,
+ "",
+ url,
+ i.Timestamp,
+ linksId,
+ "",
+ isAlarm,
+ 0,
+ 0,
+ 0,
+ targetInfos,
+ }
+ requstbody, err := json.Marshal(peraction)
+
+ 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杩斿洖鐨勬暟鎹俊鎭槸锛�", resp1)
+ // 鍙戝嚭褰曞儚淇″彿
+ ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, ImgId: i.Id, SdkIds: []string{}, Type: 2})
+ logger.Warn("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
+ //os.Exit(1)
+ }
+ }
} else {
- isAlarm = "0"
- // 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
- return
- }
- log.Println("鍥剧墖涓婁紶杩斿洖鍊硷細", resp)
- // 鏌ヨ鏈満淇℃伅
- flag, localConfig := dbapi.SysSetApi{}.GetServerInfo()
- if !flag {
- log.Println("鏌ヨ鏈満淇℃伅澶辫触锛�")
- }
- // 鏌ヨcameraName
- camera, err := dbapi.CameraApi{}.GetCameraById(msg.Cid)
- if err != nil {
- log.Println("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
- }
- serverIp, err := GetLocalIP()
- peraction := Personaction{
- uuid.NewV4().String(),
- msg.Cid,
- camera.Name,
- msg.Caddr,
- msg.Tasklab.Taskid,
- msg.Tasklab.Taskname,
- sdkNames,
- "",
- alarmRules,
- localConfig.ServerId,
- localConfig.ServerName,
- serverIp,
- "",
- []string{strings.Split(resp["fileUrl"].(string), "/")[1]},
- time.Now().Format("2006-01-02 15:04:05"),
- "",
- isAlarm,
- "",
- "",
- 0,
- }
- requstbody, err := json.Marshal(peraction)
-
- if err != nil {
- log.Println("json parse error ", err)
- return
-
- }
- err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody)
- if err != nil {
- log.Println("es can not execute right.")
+ logger.Debug("timeLabel鏉′欢閮戒笉绗﹀悎锛�")
}
}
}
@@ -277,3 +561,58 @@
err = errors.New("ipv4 not found")
return
}
+
+// 鎶婃姤璀︾瓑绾ц浆鍖栨垚姹夊瓧
+func ChangeToString(defenceState bool, i int32) string {
+ alarm := ""
+ if defenceState {
+ if i == 1 {
+ alarm = "涓�绾�"
+ }
+ if i == 2 {
+ alarm = "浜岀骇"
+ }
+ if i == 3 {
+ alarm = "涓夌骇"
+ }
+ if i == 4 {
+ alarm = "鍥涚骇"
+ }
+ if i == 5 {
+ alarm = "浜旂骇"
+ }
+ } else {
+ alarm = "鎾ら槻"
+ }
+
+ return alarm
+}
+
+//鑾峰彇骞撮緞鎻忚堪
+func getDescription(age int32) string {
+ ageInfo := "闈掑勾"
+ if age > 0 && age < 7 {
+ ageInfo = "绔ュ勾"
+ } else if age >= 7 && age < 18 {
+ ageInfo = "灏戝勾"
+ } else if age >= 18 && age < 40 {
+ ageInfo = "闈掑勾"
+ } else if age >= 40 && age < 65 {
+ ageInfo = "涓勾"
+ } else if age >= 65 {
+ ageInfo = "鑰佸勾"
+ }
+ return ageInfo
+}
+
+func getRaceString(i int32) string {
+ race := ""
+ if i == 1 {
+ race = "鐧戒汉"
+ } else if i == 2 {
+ race = "榛勪汉"
+ } else {
+ race = "榛戜汉"
+ }
+ return race
+}
--
Gitblit v1.8.0