From 9d456d237fbf9f830d1a666f553579bc5ec9f479 Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期六, 22 六月 2019 17:57:40 +0800 Subject: [PATCH] 更改矩形的计算方式 --- main.go | 59 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 64321ca..2e237a1 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,9 @@ import ( "fmt" "ruleprocess/ruleserver" - "sync" + "ruleprocess/insertdata" + "sync" "basic.com/pubsub/protomsg.git" "basic.com/valib/deliver.git" "github.com/golang/protobuf/proto" @@ -39,10 +40,14 @@ } else { arg := ruleserver.ArgsFromSdk{} m := paramFormat(msg,&arg) - arg.MainJudge() + fmt.Println("瑙f瀽鍑烘潵鐨勬暟鎹細",arg) + ruleserver.MainJudge(&arg) // 鎶奱rg閲岀殑鎵撶殑鏍囩鎷垮嚭鏉ョ粰m鍐嶅皝瑁呬竴灞� resultMag := ruleserver.ResultMsg{SdkMessage: m, RuleResult: arg.RuleResult} - fmt.Println("鎵撳畬鏍囩鍚庣殑缁撴灉锛�",resultMag) + //fmt.Println("鎵撳畬鏍囩鍚庣殑缁撴灉锛�",resultMag) + + // 灏嗘墦瀹屾爣绛剧殑鏁版嵁鎻掑叆鍒癊S + insertdata.InsertToEs(resultMag) } } } @@ -50,48 +55,72 @@ // 灏嗗閮ㄤ紶杩涙潵鐨剆dk鏁版嵁鍖呰В鎴� ArgsFromSdk func paramFormat(msg []byte,arg *ruleserver.ArgsFromSdk) protomsg.SdkMessage { + defer func() { + if err := recover();err != nil{ + fmt.Println("瑙e寘杩囩▼鐨勯敊璇�",err.(string)) + } + + }() // 鍙嶅簭鍒楀寲鏁版嵁寰楀埌sdk鍏ュ弬 m := protomsg.SdkMessage{} err := proto.Unmarshal(msg, &m) if err != nil { - fmt.Println("瑙f瀽msg鏃跺嚭鐜伴敊璇�", err) - return m + panic("瑙f瀽msg鏃跺嚭鐜伴敊璇�") } arg.CameraId = m.Cid arg.TaskId = m.Tasklab.Taskid - + bdata,err := UnCompress(m.Data) + if err != nil { + panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒") + } i := protomsg.Image{} - err = proto.Unmarshal(m.Data, &i) + err = proto.Unmarshal(bdata, &i) arg.ImageWidth = int(i.Width) arg.ImageHeight = int(i.Height) // 鏆傛椂鍐欐锛宻dk杩樻病鏈夎繖淇╃畻娉� arg.KeepRight = false arg.IsStatic = false fmt.Println("浠巑ongos涓嬁鍒扮殑鏁版嵁鍖呴暱搴︿负锛�", len(msg)) - for _, sdkinfo := range m.Tasklab.Sdkinfos { - if sdkinfo.Sdktype == "yolo" { + for _, sdkinfo := range m.Tasklab.Sdkinfos { // yolo绠楁硶 + if sdkinfo.Sdktype == "Yolo" { yoloParam := protomsg.ParamYoloObj{} err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam) if err != nil { - fmt.Println("瑙f瀽sdk鏁版嵁鏃跺嚭鐜伴敊璇�", err) - continue + fmt.Println("瑙f瀽YOLO sdk鏁版嵁鏃跺嚭鐜伴敊璇�", err) + //continue } for _, info := range yoloParam.Infos { - photoMap := ruleserver.PhotoMap{Rects:rectFormat(info.RcObj, i.Width, i.Height), Score: float64(info.Prob)} + photoMap := ruleserver.PhotoMap{Rects:rectFormat(info.RcObj), Score: float64(info.Prob)} arg.Photo = append(arg.Photo, photoMap) } } + if sdkinfo.Sdktype == "FaceDetect" { // 浜鸿劯妫�娴� + faceParam := protomsg.ParamFacePos{} + err = proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) + if err != nil { + fmt.Println("瑙f瀽FACE sdk鏁版嵁鏃跺嚭鐜伴敊璇�", err) + continue + } + for _, info := range faceParam.Faces { + photoMap := ruleserver.PhotoMap{Rects:ruleserver.Rect{}, Score: float64(info.Pos.Quality)} + arg.Photo = append(arg.Photo, photoMap) + } + } + //if sdkinfo.Sdktype == "FaceExtract" { // 浜鸿劯鎻愬彇 + + //} + } return m } // 灏嗗閮ㄤ紶杩涙潵鐨剅ect锛坱op,bottom,left,right锛夎浆鍖栦负鑷繁鍐呴儴鐨剅ect(left top width height) -func rectFormat(rcobj *protomsg.Rect, width int32, height int32) ruleserver.Rect { +func rectFormat(rcobj *protomsg.Rect) ruleserver.Rect { rect := ruleserver.Rect{} rect.X = float64(rcobj.Left) rect.Y = float64(rcobj.Top) - rect.Width = float64(width - rcobj.Left - rcobj.Right) - rect.Height = float64(height - rcobj.Top - rcobj.Bottom) + rect.Width = float64(rcobj.Right - rcobj.Left) + rect.Height = float64(rcobj.Bottom - rcobj.Top) return rect } -- Gitblit v1.8.0