| | |
| | | "context" |
| | | "fmt" |
| | | "plugin" |
| | | "time" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | |
| | | type VehicleDetector struct { |
| | | licSrvPath string |
| | | modelPath string |
| | | |
| | | list *LockList |
| | | |
| | | handle interface{} |
| | | fnInit func(int, int, string, string, func(...interface{})) interface{} |
| | |
| | | licSrvPath: licSrv, |
| | | modelPath: model, |
| | | |
| | | list: NewLockList(6), |
| | | |
| | | handle: nil, |
| | | fnInit: fnInit.(func(int, int, string, string, func(...interface{})) interface{}), |
| | | fnFree: fnFree.(func(interface{})), |
| | |
| | | return true |
| | | } |
| | | |
| | | func (d *VehicleDetector) 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) |
| | | return |
| | | } |
| | | |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | |
| | | vehicle := d.fnRun(d.handle, i.Data, imgW, imgH, 3, 0, 0, imgW, imgH) |
| | | plateids := convert2ProtoPlateIDResultVehicle(vehicle) |
| | | |
| | | plateresult := protomsg.PlateIDResult{Result: plateids} |
| | | data, err := proto.Marshal(&plateresult) |
| | | if err != nil { |
| | | fmt.Println("PLATE ID DETECTOR MARSHAL PROTO PLATE IDS ERROR", err) |
| | | data = nil |
| | | } |
| | | |
| | | ejectResult(data, rMsg, out) |
| | | |
| | | var id, name string |
| | | if rMsg.Msg.Tasklab != nil { |
| | | id, name = rMsg.Msg.Tasklab.Taskid, rMsg.Msg.Tasklab.Taskname |
| | | } |
| | | logo.Infoln("CAMERAID: ", rMsg.Msg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT VEHICLE PLATE ID COUNT: ", len(vehicle)) |
| | | |
| | | } |
| | | |
| | | // Run impl |
| | | func (d *VehicleDetector) Run(ctx context.Context, in <-chan work.MsgRS, out chan<- work.MsgRS, typ string) { |
| | | tm := time.Now() |
| | | sc := 0 |
| | | |
| | | for { |
| | | select { |
| | | case <-ctx.Done(): |
| | | d.fnFree(d.handle) |
| | | return |
| | | default: |
| | | rMsg := <-in |
| | | if !validRemoteMessage(rMsg, typ) { |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | |
| | | i := unpackImage(rMsg, typ) |
| | | if i == nil || i.Data == nil || i.Width <= 0 || i.Height <= 0 { |
| | | ejectResult(nil, rMsg, out) |
| | | continue |
| | | } |
| | | |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | |
| | | vehicle := d.fnRun(d.handle, i.Data, imgW, imgH, 3, 0, 0, imgW, imgH) |
| | | plateids := convert2ProtoPlateIDResultVehicle(vehicle) |
| | | |
| | | plateresult := protomsg.PlateIDResult{Result: plateids} |
| | | data, err := proto.Marshal(&plateresult) |
| | | if err != nil { |
| | | fmt.Println("PLATE ID DETECTOR MARSHAL PROTO PLATE IDS ERROR", err) |
| | | data = nil |
| | | } |
| | | |
| | | ejectResult(data, rMsg, out) |
| | | |
| | | var id, name string |
| | | if rMsg.Msg.Tasklab != nil { |
| | | id, name = rMsg.Msg.Tasklab.Taskid, rMsg.Msg.Tasklab.Taskname |
| | | } |
| | | logo.Infoln("CAMERAID: ", rMsg.Msg.Cid, " TASKID: ", id, " TASKNAME: ", name, " DETECT VEHICLE PLATE ID COUNT: ", len(vehicle)) |
| | | |
| | | 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() |
| | | } |
| | | |
| | | } |
| | | } |
| | | FlowSimple(ctx, in, out, typ, d.list.Push, d.list.Pop, d.detect, func() { d.fnFree(d.handle) }) |
| | | } |
| | | |
| | | func convert2ProtoPlateIDResultVehicle(obj []sdkstruct.CVehicleITSResult) []*protomsg.PlateIDVehicle { |
| | |
| | | } |
| | | return ret |
| | | } |
| | | |
| | | // hr := convert2ProtoHumanTrackResult(res) |
| | | // result := protomsg.HumanTrackResult{Result: hr[0]} |
| | | // data, err := proto.Marshal(&result) |
| | | // if err != nil { |
| | | // fmt.Println("HUMAN TRACKER MARSHAL PROTO PLATE IDS ERROR", err) |
| | | // data = nil |
| | | // } |
| | | |
| | | // func convert2ProtoHumanTrackResult(obj []sdkstruct.FgResult) [][]*protomsg.HumanTrack { |
| | | // ret := [][]*protomsg.HumanTrack{} |
| | | // for _, v := range obj { |
| | | // res := []*protomsg.HumanTrack{} |
| | | // for i := 0; i < int(v.FgNum); i++ { |
| | | // r := v.Fginfo[i] |
| | | |
| | | // rect := protomsg.Rect{ |
| | | // Left: r.Left, |
| | | // Right: r.Right, |
| | | // Top: r.Top, |
| | | // Bottom: r.Bottom, |
| | | // } |
| | | // pr := &protomsg.HumanTrack{ |
| | | // RcHuman: &rect, |
| | | // Confidence: r.Confidence, |
| | | // X: r.X, |
| | | // Y: r.Y, |
| | | // Id: r.ID, |
| | | // Feature: r.Feature[:], |
| | | // } |
| | | // res = append(res, pr) |
| | | // } |
| | | // ret = append(ret, res) |
| | | // } |
| | | // return ret |
| | | // } |