From e4752918e2291ef777ea24030773acb7f3b3a4d2 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期六, 29 六月 2019 18:38:18 +0800
Subject: [PATCH] ---注释
---
main.go | 143 +++++++++++++++++++++++++++++++++--------------
1 files changed, 99 insertions(+), 44 deletions(-)
diff --git a/main.go b/main.go
index 6b5506e..6dec348 100644
--- a/main.go
+++ b/main.go
@@ -2,12 +2,14 @@
import (
"fmt"
+ "ruleprocess/insertdata"
"ruleprocess/ruleserver"
- "sync"
- "analysis/work"
+ "ruleprocess/util"
+
"basic.com/pubsub/protomsg.git"
"basic.com/valib/deliver.git"
"github.com/golang/protobuf/proto"
+ "sync"
)
func main() {
@@ -37,23 +39,36 @@
fmt.Println("recv error : ", err)
continue
} else {
- arg := ruleserver.ArgsFromSdk{}
- m := paramFormat(msg,&arg)
- fmt.Println("瑙f瀽鍑烘潵鐨勬暟鎹細",arg)
- ruleserver.MainJudge(&arg)
+ arg := ruleserver.SdkDatas{}
+ m := paramFormat(msg, &arg)
+ fmt.Println("瑙f瀽鍑烘潵鐨勬暟鎹細", arg)
+ ruleserver.Judge(&arg)
// 鎶奱rg閲岀殑鎵撶殑鏍囩鎷垮嚭鏉ョ粰m鍐嶅皝瑁呬竴灞�
resultMag := ruleserver.ResultMsg{SdkMessage: m, RuleResult: arg.RuleResult}
- fmt.Println("鎵撳畬鏍囩鍚庣殑缁撴灉锛�",resultMag)
+ //fmt.Println("鎵撳畬鏍囩鍚庣殑缁撴灉锛�",resultMag)
+
+ // 灏嗘墦瀹屾爣绛剧殑鏁版嵁鎻掑叆鍒癊S
+ insertdata.InsertToEs(resultMag)
}
}
}
}
-// 灏嗗閮ㄤ紶杩涙潵鐨剆dk鏁版嵁鍖呰В鎴� ArgsFromSdk
-func paramFormat(msg []byte,arg *ruleserver.ArgsFromSdk) protomsg.SdkMessage {
+// 灏嗗閮ㄤ紶杩涙潵鐨剅ect锛坱op,bottom,left,right锛夎浆鍖栦负鑷繁鍐呴儴鐨剅ect(left top width height)
+func rectFormat(rcobj *protomsg.Rect) ruleserver.Rect {
+ rect := ruleserver.Rect{}
+ rect.X = float64(rcobj.Left)
+ rect.Y = float64(rcobj.Top)
+ rect.Width = float64(rcobj.Right - rcobj.Left)
+ rect.Height = float64(rcobj.Bottom - rcobj.Top)
+ return rect
+}
+
+// 灏嗗閮ㄤ紶杩涙潵鐨剆dk鏁版嵁鍖呰В鎴� SdkDatas
+func paramFormat(msg []byte, args *ruleserver.SdkDatas) protomsg.SdkMessage {
defer func() {
- if err := recover();err != nil{
- fmt.Println("瑙e寘杩囩▼鐨勯敊璇�",err.(string))
+ if err := recover(); err != nil {
+ fmt.Println("瑙e寘杩囩▼鐨勯敊璇�", err.(string))
}
}()
@@ -63,44 +78,84 @@
if err != nil {
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(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 {
+ args.CameraId = m.Cid
+ for _, sdkinfo := range m.Tasklab.Sdkinfos { // yolo绠楁硶
if sdkinfo.Sdktype == "Yolo" {
- yoloParam := protomsg.ParamYoloObj{}
- err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam)
+ arg := ruleserver.SdkData{}
+ arg.TaskId = m.Tasklab.Taskid
+ arg.SdkId = sdkinfo.Sdkid
+ arg.SdkName = sdkinfo.SdkName
+ arg.IsYolo = true
+ bdata, err := util.UnCompress(m.Data)
if err != nil {
- fmt.Println("瑙f瀽sdk鏁版嵁鏃跺嚭鐜伴敊璇�", err)
- continue
+ panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
}
- for _, info := range yoloParam.Infos {
- photoMap := ruleserver.PhotoMap{Rects:rectFormat(info.RcObj, i.Width, i.Height), Score: float64(info.Prob)}
- arg.Photo = append(arg.Photo, photoMap)
+ i := protomsg.Image{}
+ err = proto.Unmarshal(bdata, &i)
+ arg.ImageWidth = int(i.Width)
+ arg.ImageHeight = int(i.Height)
+ // 鏆傛椂鍐欐锛宻dk杩樻病鏈夎繖淇╃畻娉�
+ arg.KeepRight = false
+ arg.IsStatic = false
+ if len(sdkinfo.Sdkdata) > 1 {
+ // 澶т簬1鎵嶆湁鏁版嵁
+ fmt.Println("----------------------------------------------------",m.Cid)
+ yoloParam := protomsg.ParamYoloObj{}
+ err = proto.Unmarshal(sdkinfo.Sdkdata, &yoloParam)
+ if err != nil {
+ fmt.Println("瑙f瀽YOLO sdk鏁版嵁鏃跺嚭鐜伴敊璇�", err)
+ continue
+ }
+ for _, info := range yoloParam.Infos {
+ if info.Typ == 0 {
+ photoMap := ruleserver.PhotoMap{Rects: rectFormat(info.RcObj), Score: float64(info.Prob)*100,IsYolo:true}
+ arg.Photo = append(arg.Photo, photoMap)
+ }
+ }
+ args.Sdkdata = append(args.Sdkdata,arg)
+ } else {
+ continue
}
}
+ if sdkinfo.Sdktype == "FaceDetect" { // 浜鸿劯妫�娴�
+ arg := ruleserver.SdkData{}
+ arg.TaskId = m.Tasklab.Taskid
+ arg.SdkId = sdkinfo.Sdkid
+ arg.SdkName = sdkinfo.SdkName
+ arg.IsYolo = false
+ bdata, err := util.UnCompress(m.Data)
+ if err != nil {
+ panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+ }
+ i := protomsg.Image{}
+ err = proto.Unmarshal(bdata, &i)
+ arg.ImageWidth = int(i.Width)
+ arg.ImageHeight = int(i.Height)
+ // 鏆傛椂鍐欐锛宻dk杩樻病鏈夎繖淇╃畻娉�
+ arg.KeepRight = false
+ arg.IsStatic = false
+ if len(sdkinfo.Sdkdata) > 1 {
+ fmt.Println("----------------------------------------------------",m.Caddr)
+ 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: rectFormat(info.Pos.RcFace), Score: float64(info.Pos.Quality)*100, IsYolo:false,ThftRes:*(info.Result)}
+ arg.Photo = append(arg.Photo, photoMap)
+ }
+ args.Sdkdata = append(args.Sdkdata,arg)
+ } else {
+ continue
+ }
+ }
+ //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 {
- 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)
- return rect
-}
+}
\ No newline at end of file
--
Gitblit v1.8.0