From 42e6fe67c0c8cb51bf8ac13460f562672fd20c3e Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期一, 09 十二月 2019 17:09:54 +0800
Subject: [PATCH] es做成so
---
insertdata/insertDataToEs.go | 903 --------------------------------------------------------
algorithm/insertEs/EsClient.go | 0
algorithm/insertEs/insertDataToEs.go | 16
algorithm/insertEs/config.go | 0
4 files changed, 7 insertions(+), 912 deletions(-)
diff --git a/insertdata/EsClient.go b/algorithm/insertEs/EsClient.go
similarity index 100%
rename from insertdata/EsClient.go
rename to algorithm/insertEs/EsClient.go
diff --git a/insertdata/config.go b/algorithm/insertEs/config.go
similarity index 100%
rename from insertdata/config.go
rename to algorithm/insertEs/config.go
diff --git a/algorithm/insertEs/insertDataToEs.go b/algorithm/insertEs/insertDataToEs.go
index 1d06682..6515807 100644
--- a/algorithm/insertEs/insertDataToEs.go
+++ b/algorithm/insertEs/insertDataToEs.go
@@ -104,20 +104,7 @@
rules []structure.Result
}
-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.AIOcean.IndexName + "/" + EsInfo.EsIndex.AIOcean.IndexType+"?refresh=true"
- serverIp = localConfig1.AlarmIp
- serverPort = strconv.Itoa(int(localConfig1.AlarmPort))
+func InsertToEs(msg structure.ResultMsg){
for k,results := range msg.RuleResult {
if results != nil && len(results.([]structure.Result)) > 0{
switch k {
@@ -135,7 +122,6 @@
}
}
}
-
// 寰�es涓彃鍏ヤ汉鑴哥被鍨嬫暟鎹�
func InsertFace(msg structure.ResultMsg,key string, results interface{}) {
logger.Info("寰�es鎻掑叆鎶撴媿鏁版嵁")
diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index 1d06682..2e70d2a 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -1,910 +1,19 @@
package insertdata
import (
- "encoding/base64"
- "encoding/json"
- "errors"
- "net"
- "strconv"
- "time"
-
- "github.com/golang/protobuf/proto"
- "github.com/satori/go.uuid"
- "basic.com/valib/logger.git"
-
- "ruleprocess/cache"
+ "plugin"
"ruleprocess/structure"
- "basic.com/pubsub/protomsg.git"
- "basic.com/pubsub/esutil.git"
- "ruleprocess/ruleserver"
- "ruleprocess/util"
)
-var weedfsUrl, videoPersonUrl, personAction string
-var serverIp string
-var serverPort 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"`
-}
-
-type LinkInfo struct {
- Id string `json:"id"`
- CameraId string `json:"cameraId"`
- CameraAddr string `json:"cameraAddr"`
- CameraName string `json:"cameraName"`
- 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"`
- ShowLabels string `json:"showLabels"`
- OtherLabels string `json:"otherLabels"`
- VideoUrl string `json:"videoUrl"`
- AnalyServerId string `json:"analyServerId"`
- AnalyServerName string `json:"analyServerName"`
- AnalyServerIp string `json:"analyServerIp"`
- ClusterId string `json:"clusterId"`
- IsAlarm bool `json:"isAlarm"`
- IsAckAlarm bool `json:"isAckAlarm"`
- IsCollect bool `json:"isCollect"`
- IsDelete bool `json:"isDelete"`
- BaseInfo []*structure.BaseInfo `json:"baseInfo"`
- TargetInfo []Target `json:"targetInfo"`
-}
-
-// 缁熶竴鐨勬暟鎹粨鏋�
-type PerVideoPicture struct {
- LinkInfo
- LinkTag string `json:"linkTag"`
- LinkTagInfo []*LinkInfo `json:"linkTagInfo"`
-}
-
-type SourceTarget struct {
- TargetId string `json:"targetId"`
- TargetScore float64 `json:"targetScore"`
- TargetType string `json:"targetType"`
- Feature string `json:"feature"`
- PicSmUrl string `json:"picSmUrl"`
- TargetLocation Points `json:"targetLocation"`
-}
-type Target struct {
- SourceTarget
- AttachTarget SourceTarget `json:"attachTarget"`
-}
-
-type Points struct {
- TopLeft Point `json:"topLeft"`
- BottomRight Point `json:"bottomRight"`
-}
-
-type Point struct {
- X float64 `json:"x"`
- Y float64 `json:"y"`
-}
-
-type AlarmRule struct {
- GroupId string `json:"groupId"`
- AlarmLevel string `json:"alarmLevel"`
- RuleText string `json:"ruleText"`
- DefenceState bool `json:"defenceState"`
- LinkInfo string `json:"linkInfo"`
-}
-
-// 涓�涓猳bj瀵瑰涓鍒欑粍鐨勫綊缃汉鑴哥殑缁撴瀯浣� 鍙敤浜庝汉鑴� 鍙敤浜庤溅鐗�
-type ObjAndRules struct {
- structure.Arg
- rules []structure.Result
-}
func InsertToEs(msg structure.ResultMsg) {
- defer func() {
- if err := recover(); err != nil {
- logger.Error("es妯″潡鍎跨殑寮傚父鎹曡幏锛�", err)
- }
- }()
- localConfig1, err := cache.GetServerInfo()
+ p,err := plugin.Open("./algorithm/insertEs.so")
if err != nil {
- panic("閰嶇疆鏂囦欢涓嶅悎娉�")
+ panic(err)
}
- weedfsUrl = "http://" + localConfig1.WebPicIp + ":" + strconv.Itoa(int(localConfig1.WebPicPort)) + "/submit"
- videoPersonUrl = "http://" + localConfig1.AlarmIp + ":" + strconv.Itoa(int(localConfig1.AlarmPort)) + "/" + EsInfo.EsIndex.AIOcean.IndexName + "/" + EsInfo.EsIndex.AIOcean.IndexType+"?refresh=true"
- serverIp = localConfig1.AlarmIp
- serverPort = strconv.Itoa(int(localConfig1.AlarmPort))
- for k,results := range msg.RuleResult {
- if results != nil && len(results.([]structure.Result)) > 0{
- switch k {
- case "yolo":
- InsertYolo(msg,k,results)
- case "face":
- InsertFace(msg,k,results)
- case "plate":
- InsertFace(msg,k,results)
- case "track":
- InsertFace(msg,k,results)
- case "target":
- InsertLastTarget(msg)
- }
- }
- }
-}
-
-// 寰�es涓彃鍏ヤ汉鑴哥被鍨嬫暟鎹�
-func InsertFace(msg structure.ResultMsg,key string, results interface{}) {
- logger.Info("寰�es鎻掑叆鎶撴媿鏁版嵁")
- faces := []*ObjAndRules{}
- faces = PutFace(faces, results.([]structure.Result))
- //logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces)
- if faces != nil {
- logger.Warn("face涓嶄负nil")
- var imgMaxUrl []string = []string{}
- var picTime string = ""
- for _, face := range faces {
- // 涓婁紶澶у浘
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- alarmRules := []AlarmRule{}
- //logger.Info("寰幆姣忎竴涓洰鏍�")
- 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),face.Type)
- resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
- if err != nil {
- logger.Error("涓婁紶灏忓浘鍑洪敊")
- }
- // 涓婁紶澶у浘
- if len(imgMaxUrl) == 0 {
- bigPhotoUrl := make(map[string]interface{})
- bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.Result), weedfsUrl)
- logger.Debug("========澶у浘璺緞锛�", bigPhotoUrl)
- imgMaxUrl = append(imgMaxUrl, bigPhotoUrl["fileUrl"].(string))
- picTime = i.Timestamp
- }
- lable, lableAttach := Feature2Jsonstr(*face)
- var target = new(Target)
- target.TargetId = face.Id
- target.TargetScore = face.Score
- target.TargetType = face.Type
- target.Feature = base64.StdEncoding.EncodeToString(face.Feature)
- target.PicSmUrl = resp["fileUrl"].(string)
- 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}}
- target.AttachTarget = SourceTarget{face.AttachArg.Id,face.AttachArg.Score,face.AttachArg.Type,base64.StdEncoding.EncodeToString(face.AttachArg.Feature),"",Points{TopLeft: Point{face.AttachArg.Location.X, face.AttachArg.Location.Y}, BottomRight: Point{face.AttachArg.Location.X + face.AttachArg.Location.Width, face.AttachArg.Location.Y + face.AttachArg.Location.Height}}}
- var targetInfos []Target
- targetInfos = append(targetInfos, *target)
-
- sdkname := ""
- id := face.Uuid
- switch key {
- case "face":
- sdkname = "浜鸿劯"
- case "plate":
- sdkname = "杞︾墝璇嗗埆"
- case "track":
- sdkname = "浜哄憳璺熻釜"
- if len(face.Liker) == 1{
- id = face.Liker[0].TargetId
- }
- }
- //logger.Info("浜鸿劯鐩爣target:",targetInfos)
-
- pervideo := PerVideoPicture{LinkInfo{
- id,
- msg.Cid,
- msg.Push.Cam.Addr,
- msg.Push.Cam.Name,
- picTime,
- imgMaxUrl,
- msg.Tasklab.Taskid,
- msg.Tasklab.Taskname,
- sdkname,
- "",
- alarmRules,
- time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
- lable,
- lableAttach,
- "",
- msg.Push.ServerId,
- msg.Push.ServerName,
- msg.Push.LocalIp,
- "",
- true,
- false,
- false,
- false,
- face.Liker,
- targetInfos,
- },
- "",
- []*LinkInfo{},
- }
- requstbody, err := json.Marshal(pervideo)
-
- if err != nil {
- logger.Info("json parse error ", err)
- return
- }
- if key == "track" && len(face.Liker) == 1{
- esid := face.Liker[0].TargetId
- returnMsg, err1 := esutil.AppendTargetInfo(esid, string(requstbody),EsInfo.EsIndex.AIOcean.IndexName,serverIp,serverPort)
- if err1 != nil {
- logger.Error("杩藉姞鏁版嵁鍑洪敊锛�---", err1)
- } else {
- logger.Info("鎻掑叆es杩斿洖鐨勪俊鎭細", returnMsg)
- // 鍙戝嚭褰曞儚淇″彿
- 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})
- }
- } else {
- 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(objs []*ObjAndRules, resutls []structure.Result) []*ObjAndRules {
- for _, faceResult := range resutls {
- objs = hebingFace(objs, faceResult)
- }
- return objs
-}
-func hebingFace(objs []*ObjAndRules, faceResult structure.Result) []*ObjAndRules {
- for _, arg := range faceResult.AlarmObj {
- // 鎷垮埌姣忎竴寮犱汉鑴�
- //logger.Info("褰掔疆浜鸿劯鏃剁浉浼艰�呯殑鏁伴噺锛�", len(arg.Liker))
- flag := false
- for _, face := range objs {
- //for _, lik := range face.Liker {
- // //logger.Warn("--------鍚堝苟浜鸿劯鏃剁浉浼艰�咃細", lik.PersonId, lik.TableName)
- //}
- if arg.Id == face.Id {
- flag = true
- face.rules = append(face.rules, faceResult)
- // 鐩镐技鑰呭幓閲嶅綊骞�
- for _, liker := range arg.Liker {
- flag1 := true
- for _, liker1 := range face.Liker {
- if liker.TargetId == liker1.TargetId {
- flag1 = false
- }
- }
- if flag1 {
- face.Liker = append(face.Liker, liker)
- }
- }
- //face.Liker = append(face.Liker,arg.Liker...)
- }
- }
- if !flag {
- objs = append(objs, &ObjAndRules{*arg, []structure.Result{faceResult}})
- }
- }
- return objs
-}
-
-// 寰�es涓彃鍏olo鏁版嵁
-func InsertYolo(msg structure.ResultMsg,key string, results interface{}) {
- // 鍏堝垽鏂竴涓嬫暟鎹甫鐨勮鍒欐爣绛炬槸鍚︽湁鍙互鎻掑叆鐨�
- 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 results.([]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("鎵撳嵃浠诲姟鍚嶇О锛�", )
- // 涓婁紶缂撳瓨鏁版嵁鐨勫浘鐗囨嬁鍒皍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.AlarmObj {
- // 鍘婚噸娣诲姞
- var flag = true
- for _, selectTarget := range targetInfos {
- if target.Id == selectTarget.TargetId {
- flag = false
- break
- }
- }
- if flag {
- var target1 = new(Target)
- target1.TargetId = target.Id
- target1.TargetScore = target.Score
- target1.TargetType = "action"
- 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)
- }
- }
- }
- }
- // 鑱斿姩鍥惧儚鐨勫鐞�
- 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 {
- // 鎶妋sg2鐨勬暟鎹閰嶆垚涓�涓狿erVideoPicture缁撴瀯浣�
- if msg2.Cid != msg.Cid {
- linkTagInfos = append(linkTagInfos, msg2PersonVideo(msg2))
- }
- }
- }
- }
- linkTag := ""
- if len(linkTagInfos) > 0 {
- linkTag = "鑱斿姩浠诲姟"
- }
- isAlarm := false
- resp := make(map[string]interface{})
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata, &i)
- if len(alarmRules) > 0 {
- isAlarm = true
- //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 = false
- // 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
- return
- }
- if resp["fileUrl"] != nil {
- url = append(url, resp["fileUrl"].(string))
- //esDataId := uuid.NewV4().String()
- peraction := PerVideoPicture{LinkInfo{
- msg.Push.PushId,
- msg.Cid,
- msg.Push.Cam.Addr,
- msg.Push.Cam.Name,
- time.Now().Format("2006-01-02 15:04:05"),
- url,
- msg.Tasklab.Taskid,
- msg.Tasklab.Taskname,
- sdkNames,
- time.Now().Format("2006-01-02 15:04:05"),
- alarmRules,
- i.Timestamp,
- "",
- "",
- "",
- msg.Push.ServerId,
- msg.Push.ServerName,
- msg.Push.LocalIp,
- "",
- isAlarm,
- false,
- false,
- false,
- nil,
- 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", videoPersonUrl, requstbody)
- if err2 != nil {
- logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
- } else {
- logger.Debug("鎻掑叆es杩斿洖鐨勬暟鎹俊鎭槸锛坹olo锛夛細", 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)
- }
- }
- }
-}
-
-// 鎻掑叆鐩爣鎸佺画鏃堕棿鏁版嵁
-
-func InsertLastTarget(msg structure.ResultMsg) {
- if msg.RuleResult["target"] != nil && len(msg.RuleResult["target"].([]structure.Result)) > 0 {
- // 鍏堝垽鏂竴涓嬫暟鎹甫鐨勮鍒欐爣绛炬槸鍚︽湁鍙互鎻掑叆鐨�
- 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 {
- if obj.TimeLable == "10" {
- insertFlag = true
- alarmNum++
- }
- }
- if insertFlag {
- logger.Info("鎶ヨ鐩爣涓暟锛�", alarmNum)
-
- // 鑾峰彇鐩爣缂撳瓨鍥剧墖
- url := []string{}
- //InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
- // 鎶婄紦瀛樼殑鏁版嵁涓婁紶鍚庡緱鍒板湴鍧�瀛樿繘鍘�
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- url1 := uploadImg(yoloResult.AlarmObj[0].CacheData)
- url = append(url, url1)
- // 娣诲姞鎶ヨ瑙勫垯缁�
- sdkNames := ""
- alarmRules := []AlarmRule{}
- 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})
- // 鑱斿姩鍥惧儚鐨勫鐞�
- linkTagInfos := []*LinkInfo{}
- for _, yoloResult := range msg.RuleResult["target"].([]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 {
- // 鎶妋sg2鐨勬暟鎹閰嶆垚涓�涓狿erVideoPicture缁撴瀯浣�
- if msg2.Cid != msg.Cid {
- linkTagInfos = append(linkTagInfos, msg2PersonVideo(msg2))
- }
- }
- }
- }
- linkTag := ""
- if len(linkTagInfos) > 0 {
- linkTag = "鑱斿姩浠诲姟"
- }
- isAlarm := false
- resp := make(map[string]interface{})
- // 瑙e帇缂╁苟涓婁紶鏈抚鏁版嵁鍥剧墖
- bdata1, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata1, &i)
- if len(alarmRules) > 0 {
- isAlarm = true
- //resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
- resp, err = util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["target"].([]structure.Result), weedfsUrl)
- if err != nil {
- logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
- return
- } else {
- logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp)
- }
- } else {
- isAlarm = false
- // 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
- return
- }
- // 鏁村悎鐩爣
- var targetInfos []Target
- for _, target := range yoloResult.AlarmObj {
- // 鍘婚噸娣诲姞
- var flag = true
- for _, selectTarget := range targetInfos {
- if target.Id == selectTarget.TargetId {
- flag = false
- break
- }
- }
- if flag {
- var target1 = new(Target)
- target1.TargetId = target.Id
- target1.TargetScore = target.Score
- target1.TargetType = "action"
- 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 resp["fileUrl"] != nil {
- url = append(url, resp["fileUrl"].(string))
- if len(url) == 1 {
- return
- }
- //esDataId := uuid.NewV4().String()
- peraction := PerVideoPicture{LinkInfo{
- msg.Push.PushId,
- msg.Cid,
- msg.Push.Cam.Addr,
- msg.Push.Cam.Name,
- i.Timestamp,
- url,
- msg.Tasklab.Taskid,
- msg.Tasklab.Taskname,
- sdkNames,
- "",
- alarmRules,
- time.Now().Format("2006-01-02 15:04:05"),
- "",
- "",
- "",
- msg.Push.ServerId,
- msg.Push.ServerName,
- msg.Push.LocalIp,
- "",
- isAlarm,
- false,
- false,
- false,
- nil,
- 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", videoPersonUrl, requstbody)
- if err2 != nil {
- logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
- } else {
- logger.Debug("鎻掑叆es杩斿洖鐨勬暟鎹俊鎭槸锛坱arget锛夛細", 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鎻掑叆target鏁版嵁鎴愬姛")
- //os.Exit(1)
- }
- }
- } else {
- logger.Info("娌℃湁棣栨鎶ヨ鐨勭洰鏍囷紝涓嶆彃鍏�")
- }
- }
- }
-}
-
-// 鑾峰彇鏈満ip
-func GetLocalIP() (ipv4 string, err error) {
- var (
- addrs []net.Addr
- addr net.Addr
- ipNet *net.IPNet // IP鍦板潃
- isIpNet bool
- )
- // 鑾峰彇鎵�鏈夌綉鍗�
- if addrs, err = net.InterfaceAddrs(); err != nil {
- return
- }
- // 鍙栫涓�涓潪lo鐨勭綉鍗P
- for _, addr = range addrs {
- // 杩欎釜缃戠粶鍦板潃鏄疘P鍦板潃: ipv4, ipv6
- if ipNet, isIpNet = addr.(*net.IPNet); isIpNet && !ipNet.IP.IsLoopback() {
- // 璺宠繃IPV6
- if ipNet.IP.To4() != nil {
- ipv4 = ipNet.IP.String() // 192.168.1.1
- return
- }
- }
- }
-
- 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 uploadImg(msg structure.ResultMsg) string {
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata, &i)
- resp1, err1 := util.DrawPolygonOnImageForTarget(msg.Cid, i, msg.RuleResult["target"].([]structure.Result), weedfsUrl)
+ f,err1 := p.Lookup("InsertToEs")
if err1 != nil {
- logger.Error("缂撳瓨鏁版嵁鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
- } else {
- logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp1)
+ panic("娌℃湁鎵惧埌涓棿浠剁殑鏍煎紡鍖栨暟鎹嚱鏁�")
}
- if resp1["fileUrl"] != nil {
- return resp1["fileUrl"].(string)
- } else {
- return ""
- }
-}
-
-//鑾峰彇骞撮緞鎻忚堪
-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
-}
-
-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("nVehicleColor1"+strconv.Itoa(int(obj.Car.NVehicleColor1))) + "杞﹁締" + "/" +
- cache.GetDic("nColor"+strconv.Itoa(int(obj.Car.NColor))) + "杞︾墝"
- lableAttach = "杞︾墝缃俊搴︼細" + strconv.Itoa(int(obj.Car.NConfidence)) + "/" + "杞︾殑浜害锛�" + strconv.Itoa(int(obj.Car.NVehicleBright)) +"/"+ "杞︾墝绫诲瀷"+cache.GetDic("nType"+strconv.Itoa(int(obj.Car.NType)))+
- "杞﹁韩杈呴鑹诧細"+cache.GetDic("nVehicleColor2"+strconv.Itoa(int(obj.Car.NVehicleColor2)))+"/"+"鏄惁璇嗗埆鍒拌溅鐗岋細"+cache.GetDic("nVehicleColor1"+strconv.Itoa(int(obj.Car.NVehicleColor1)))+"/"+
- "杞﹁締缃俊搴�"+strconv.Itoa(int(obj.Score))+"/"+"鍝佺墝锛�" +obj.Car.VehicleType1
- }
- return lable, lableAttach
-}
-
-func msg2PersonVideo(msg structure.ResultMsg) *LinkInfo {
- 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("鎻掑叆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})
- // 涓婁紶缂撳瓨鏁版嵁鐨勫浘鐗囨嬁鍒皍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.AlarmObj {
- // 鍘婚噸娣诲姞
- var flag = true
- for _, selectTarget := range targetInfos {
- if target.Id == selectTarget.TargetId {
- flag = false
- break
- }
- }
- 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)
- }
- }
- }
- }
- isAlarm := false
- resp := make(map[string]interface{})
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata, &i)
- if len(alarmRules) > 0 {
- isAlarm = true
- //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 nil
- } else {
- logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp)
- }
- } else {
- isAlarm = false
- // 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
- return nil
- }
- if resp["fileUrl"] != nil {
- url = append(url, resp["fileUrl"].(string))
- //esDataId := uuid.NewV4().String()
- pervideo := &LinkInfo{
- msg.Push.PushId + "-" + uuid.NewV4().String(),
- msg.Cid,
- msg.Push.Cam.Addr,
- msg.Push.Cam.Name,
- i.Timestamp,
- []string{resp["fileUrl"].(string)},
- msg.Tasklab.Taskid,
- msg.Tasklab.Taskname,
- "浜鸿劯",
- "",
- alarmRules,
- time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
- "",
- "",
- "",
- msg.Push.ServerId,
- msg.Push.ServerName,
- msg.Push.LocalIp,
- "",
- isAlarm,
- false,
- false,
- false,
- nil,
- targetInfos,
- }
- return pervideo
- } else {
- return nil
- }
- } else {
- logger.Debug("timeLabel鏉′欢閮戒笉绗﹀悎锛�")
- return nil
- }
- } else {
- return nil
- }
+ f.(func(msg structure.ResultMsg))(msg)
}
--
Gitblit v1.8.0