From 0d08415bcbc5d1b260861365f26b0532771da2c5 Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期日, 29 九月 2019 14:10:41 +0800 Subject: [PATCH] 人脸也画规则框 --- insertdata/insertDataToEs.go | 67 +++++++++++++++++++-------------- 1 files changed, 38 insertions(+), 29 deletions(-) diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go index 17f8053..26bb24b 100644 --- a/insertdata/insertDataToEs.go +++ b/insertdata/insertDataToEs.go @@ -1,19 +1,16 @@ package insertdata import ( + "basic.com/valib/logger.git" "encoding/base64" "encoding/json" "errors" - "fmt" - "io/ioutil" "net" "ruleprocess/cache" - "ruleprocess/logger" "strconv" "time" "basic.com/pubsub/protomsg.git" - "github.com/go-yaml/yaml" "github.com/golang/protobuf/proto" "github.com/satori/go.uuid" "ruleprocess/ruleserver" @@ -31,19 +28,11 @@ DbTablePersons string `yaml:"dbTablePersons"` } -func init() { - data, err := ioutil.ReadFile("./config/conf.yml") - if err != nil { - fmt.Println("璇诲彇閰嶇疆鏂囦欢鍑洪敊--", err) - logger.Error("璇诲彇閰嶇疆鏂囦欢鍑洪敊--", err) - } - c := conf{} - //鎶妝aml褰㈠紡鐨勫瓧绗︿覆瑙f瀽鎴恠truct绫诲瀷 - yaml.Unmarshal(data, &c) - weedfsUrl = c.PhotoUrl - videoPersonUrl = c.VideoPersons - personAction = c.PersonAction -} +//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 { @@ -145,6 +134,18 @@ // //} //} func InsertToEs(msg ruleserver.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) @@ -170,6 +171,8 @@ faces = PutFace(faces,msg) //logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces) if faces != nil { + var imgMaxUrl string = "" + var picTime string = "" for _,face := range faces { // 涓婁紶澶у浘 // 瑙e帇缂╁苟涓婁紶鍥剧墖 @@ -186,9 +189,13 @@ } i := protomsg.Image{} err = proto.Unmarshal(bdata, &i) - bigPhotoUrl := make(map[string]interface{}) - bigPhotoUrl, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String()) - logger.Debug("========澶у浘璺緞锛�", bigPhotoUrl) + if imgMaxUrl == "" { + bigPhotoUrl := make(map[string]interface{}) + bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]ruleserver.FaceResult), weedfsUrl) + logger.Debug("========澶у浘璺緞锛�", bigPhotoUrl) + imgMaxUrl = bigPhotoUrl["fileUrl"].(string) + picTime = i.Timestamp + } // 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛� localConfig, err := cache.GetServerInfo() if err != nil { @@ -221,23 +228,23 @@ if linkId != "" { linksId = linkId } - logger.Info("浜鸿劯鐨刬d:",strconv.FormatUint(face.Id, 10)) - logger.Info("浜鸿劯鐨勫垎鍊硷細",face.Score) + //logger.Info("浜鸿劯鐨刬d:",strconv.FormatUint(face.Id, 10)) + //logger.Info("浜鸿劯鐨勫垎鍊硷細",face.Score) pervideo := PerVideoPicture{ esDataId, msg.Cid, camera.Addr, - i.Timestamp, - bigPhotoUrl["fileUrl"].(string), + picTime, + imgMaxUrl, msg.Tasklab.Taskid, msg.Tasklab.Taskname, "浜鸿劯", "", alarmRules, time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿 - strconv.FormatUint(face.Id, 10), //鏆傛敼涓轰汉鑴竔d strconv.FormatUint(face.Id, 10) + sex, //鏆傛敼涓轰汉鑴竔d strconv.FormatUint(face.Id, 10) face.ThftRes.Age, - fmt.Sprintf("%.2f",face.Score), // 鏆傛敼涓哄垎鍊糵mt.Sprintf("%.2f",face.Score) + ageDescription, // 鏆傛敼涓哄垎鍊糵mt.Sprintf("%.2f",face.Score) race, face.ThftRes.Smile, face.ThftRes.Beauty, @@ -360,13 +367,15 @@ } 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"].([]ruleserver.Result), weedfsUrl) if err1 != nil { logger.Error("缂撳瓨鏁版嵁鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err) } else { logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp1) } - url = append(url, resp1["fileUrl"].(string)) + if resp1["fileUrl"] != nil { + url = append(url, resp1["fileUrl"].(string)) + } } } } @@ -401,7 +410,7 @@ 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"].([]ruleserver.Result), weedfsUrl) if err != nil { logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err) return -- Gitblit v1.8.0