| | |
| | | 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) { |
| | |
| | | |
| | | // 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 { |
| | |
| | | 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 { |