From d8d2bc7b4cf8e4a1f2b2a325d2ca02f0eb409d9c Mon Sep 17 00:00:00 2001 From: zhangmeng <zhangmeng@aiotlink.com> Date: 星期四, 19 十二月 2019 16:25:24 +0800 Subject: [PATCH] up --- work/sdk/yolotrack.go | 86 ++---------------------------------------- 1 files changed, 5 insertions(+), 81 deletions(-) diff --git a/work/sdk/yolotrack.go b/work/sdk/yolotrack.go index a4d309f..34a468d 100644 --- a/work/sdk/yolotrack.go +++ b/work/sdk/yolotrack.go @@ -1,90 +1,19 @@ package sdk import ( - "analysis/goconv" "analysis/logo" "analysis/work" "context" - "time" + + "analysis/gosdk" "basic.com/pubsub/protomsg.git" - "basic.com/valib/gosdk.git" "github.com/gogo/protobuf/proto" ) func (y *YoloDetect) detectTrack(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { y.tracker = make(map[string]*trackInfo) - go y.work(ctx, out, typ) - - for { - select { - case <-ctx.Done(): - return - default: - rMsg := <-in - if !validRemoteMessage(rMsg, typ) { - logo.Errorln("yolo validremotemessage invalid") - ejectResult(nil, rMsg, out) - continue - } - y.push(rMsg) - } - } -} - -func (y *YoloDetect) push(data work.MsgRS) { - y.cv.L.Lock() - y.cache.PushBack(data) - if y.cache.Len() > 12 { - for i := 0; i < y.cache.Len(); { - y.cache.Remove(y.cache.Front()) - i = i + 2 - } - } - // logo.Infof("push to cache count : %d\n", t.cache.Len()) - y.cond = true - y.cv.Signal() - y.cv.L.Unlock() -} - -func (y *YoloDetect) work(ctx context.Context, out chan<- work.MsgRS, typ string) { - tm := time.Now() - sc := 0 - - for { - select { - case <-ctx.Done(): - goconv.Free() - return - default: - - y.cv.L.Lock() - - for !y.cond { - y.cv.Wait() - } - - rMsg := y.cache.Front().Value.(work.MsgRS) - - y.track(rMsg, out, typ) - y.cache.Remove(y.cache.Front()) - y.cond = false - y.cv.L.Unlock() - - sc++ - if sc == 25 { - logo.Infoln("YOLO RUN 25 FRAME USE TIME: ", time.Since(tm)) - sc = 0 - tm = time.Now() - } - if time.Since(tm) > time.Second { - logo.Infof("YOLO RUN %d FRAME USE TIME: %v", sc, time.Since(tm)) - sc = 0 - tm = time.Now() - } - } - } - + FlowSimple(ctx, in, out, typ, y.list.Push, y.list.Pop, y.track, func() {}) } func (y *YoloDetect) track(rMsg work.MsgRS, out chan<- work.MsgRS, typ string) { @@ -100,12 +29,8 @@ // conv to bgr24 and resize imgW, imgH := int(i.Width), int(i.Height) - bgrData := goconv.YUV2BGR(i.Data, imgW, imgH) - if bgrData == nil { - ejectResult(nil, rMsg, out) - return - } - img := gosdk.SDKImage{Data: bgrData, Width: imgW, Height: imgH} + + img := gosdk.SDKImage{Data: i.Data, Width: imgW, Height: imgH} v, ok := y.tracker[rMsg.Msg.Cid] if !ok { @@ -152,7 +77,6 @@ id, name = rMsg.Msg.Tasklab.Taskid, rMsg.Msg.Tasklab.Taskname } logo.Infoln("CAMERAID: ", rMsg.Msg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT YOLO COUNT: ", len(allO)) - } func convert2ProtoYoloTrack(obj []gosdk.CObjTrackInfo, fx, fy float64) []*protomsg.ObjInfo { -- Gitblit v1.8.0