| | |
| | | "analysis/logo" |
| | | "analysis/work" |
| | | "context" |
| | | "time" |
| | | |
| | | "basic.com/valib/gosdk.git" |
| | | ) |
| | |
| | | cfgCloud *gosdk.CPlateIDCloudCfg |
| | | licSrvPath string |
| | | modelPath string |
| | | list *LockList |
| | | fn func(*gosdk.SDKImage, *gosdk.CRECT, int, int, *work.MsgRS, chan<- work.MsgRS) |
| | | } |
| | | |
| | |
| | | return &PlateIDDetector{ |
| | | licSrvPath: licSrv, |
| | | modelPath: model, |
| | | list: NewLockList(6), |
| | | fn: vehicle, |
| | | } |
| | | } |
| | |
| | | cfgCloud: nil, |
| | | licSrvPath: licSrv, |
| | | modelPath: "", |
| | | list: NewLockList(6), |
| | | fn: eparking, |
| | | } |
| | | |
| | |
| | | cfgCloud: cfg, |
| | | licSrvPath: licSrv, |
| | | modelPath: model, |
| | | list: NewLockList(6), |
| | | fn: cloud, |
| | | } |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | // Free free |
| | | func (d *PlateIDDetector) Free() { |
| | | if d.config != nil { |
| | | gosdk.FreePlateIdDetector() |
| | | } else if d.cfgCloud != nil { |
| | | gosdk.FreePlateIDCloudSDKDetector() |
| | | } else { |
| | | gosdk.FreeVehicleITSDetector() |
| | | } |
| | | } |
| | | |
| | | // Init impl |
| | |
| | | return true |
| | | } |
| | | |
| | | // Run impl |
| | | func (d *PlateIDDetector) Run(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | tm := time.Now() |
| | | sc := 0 |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | return |
| | | default: |
| | | rMsg := <-in |
| | | if !validRemoteMessage(rMsg, typ) { |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | |
| | | func (d *PlateIDDetector) detect(rMsg work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | i := unpackImage(rMsg, typ) |
| | | if i == nil || i.Data == nil || i.Width <= 0 || i.Height <= 0 { |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | return |
| | | } |
| | | |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | |
| | | mW, mH = int(d.config.MaxImageWidth), int(d.config.MaxImageHeight) |
| | | } |
| | | d.fn(&img, &rcDetect, mW, mH, &rMsg, out) |
| | | |
| | | sc++ |
| | | if sc == 25 { |
| | | logo.Infoln("PLATE ID DETECTOR RUN 25 FRAME USE TIME: ", time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | |
| | | if time.Since(tm) > time.Second { |
| | | logo.Infof("PLATE ID DETECTOR RUN %d FRAME USE TIME: %v", sc, time.Since(tm)) |
| | | sc = 0 |
| | | tm = time.Now() |
| | | } |
| | | |
| | | } |
| | | } |
| | | // Run impl |
| | | func (d *PlateIDDetector) Run(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | FlowSimple(ctx, in, out, typ, d.list.Push, d.list.Pop, d.detect, func() { d.Free() }) |
| | | } |
| | | |
| | | func eparking(img *gosdk.SDKImage, rc *gosdk.CRECT, mW, mH int, rMsg *work.MsgRS, out chan<- work.MsgRS) { |
| | |
| | | import ( |
| | | "analysis/logo" |
| | | "analysis/work" |
| | | "container/list" |
| | | "context" |
| | | "sync" |
| | | |
| | | "basic.com/valib/gogpu.git" |
| | | |
| | |
| | | |
| | | tracker map[string]*trackInfo |
| | | |
| | | cache *list.List |
| | | cv *sync.Cond |
| | | cond bool |
| | | list *LockList |
| | | } |
| | | |
| | | // NewYDetectWithTrack with track |
| | |
| | | cfg: cfg, |
| | | weights: weights, |
| | | name: name, |
| | | cache: list.New(), |
| | | cv: sync.NewCond(&sync.Mutex{}), |
| | | cond: false, |
| | | list: NewLockList(6), |
| | | } |
| | | } |
| | | |
| | |
| | | // Run impl interface |
| | | func (y *YoloDetect) Run(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | y.detectTrack(ctx, in, out, typ) |
| | | |
| | | } |
| | |
| | | "analysis/logo" |
| | | "analysis/work" |
| | | "context" |
| | | "time" |
| | | |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/gosdk.git" |
| | |
| | | |
| | | 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(): |
| | | 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() { gosdk.Free() }) |
| | | } |
| | | |
| | | func (y *YoloDetect) track(rMsg work.MsgRS, out chan<- work.MsgRS, typ string) { |