| | |
| | | import ( |
| | | "analysis/logo" |
| | | "analysis/work" |
| | | "container/list" |
| | | "context" |
| | | "fmt" |
| | | "plugin" |
| | | "sync" |
| | | "time" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | |
| | | weights string |
| | | name string |
| | | |
| | | cache *list.List |
| | | cv *sync.Cond |
| | | cond bool |
| | | list *LockList |
| | | |
| | | handle interface{} |
| | | fnInit func(string, string, string, int, func(...interface{})) interface{} |
| | |
| | | cfg: cfg, |
| | | weights: weights, |
| | | name: name, |
| | | cache: list.New(), |
| | | cv: sync.NewCond(&sync.Mutex{}), |
| | | cond: false, |
| | | |
| | | list: NewLockList(6), |
| | | |
| | | handle: nil, |
| | | fnInit: fnInit.(func(string, string, string, int, func(...interface{})) interface{}), |
| | |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | y.push(rMsg) |
| | | y.list.Push(rMsg) |
| | | } |
| | | } |
| | | |
| | |
| | | logo.Infoln("CAMERAID: ", rMsg.Msg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT YOLO COUNT: ", len(whole)) |
| | | } |
| | | |
| | | func (y *YoloDetect) work(ctx context.Context, out chan<- work.MsgRS, typ string) { |
| | | tm := time.Now() |
| | | sc := 0 |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | return |
| | | default: |
| | | |
| | | rMsg := y.list.Pop().(work.MsgRS) |
| | | |
| | | y.track(rMsg, out, typ) |
| | | |
| | | 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() |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | func convert2ProtoYoloTrack(obj []sdkstruct.CObjTrackInfo, fx, fy float64) []*protomsg.ObjInfo { |
| | | ret := []*protomsg.ObjInfo{} |
| | | |
| | |
| | | ret = append(ret, &obj) |
| | | } |
| | | return ret |
| | | } |
| | | |
| | | func (y *YoloDetect) work(ctx context.Context, out chan<- work.MsgRS, typ string) { |
| | | tm := time.Now() |
| | | sc := 0 |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | 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() |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | 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() |
| | | } |