From c8215ae1ce2825dca6a003c27fc721e86ae85e38 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期二, 17 十二月 2019 10:01:15 +0800 Subject: [PATCH] update --- work/sdk/vdetect.go | 127 +++++++++++------------------------------- 1 files changed, 34 insertions(+), 93 deletions(-) diff --git a/work/sdk/vdetect.go b/work/sdk/vdetect.go index 2c63000..2ee2903 100644 --- a/work/sdk/vdetect.go +++ b/work/sdk/vdetect.go @@ -6,7 +6,6 @@ "context" "fmt" "plugin" - "time" "basic.com/libgowrapper/sdkstruct.git" "basic.com/pubsub/protomsg.git" @@ -17,6 +16,8 @@ type VehicleDetector struct { licSrvPath string modelPath string + + list *LockList handle interface{} fnInit func(int, int, string, string, func(...interface{})) interface{} @@ -42,6 +43,8 @@ licSrvPath: licSrv, modelPath: model, + list: NewLockList(6), + handle: nil, fnInit: fnInit.(func(int, int, string, string, func(...interface{})) interface{}), fnFree: fnFree.(func(interface{})), @@ -63,64 +66,38 @@ 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 { @@ -179,39 +156,3 @@ } 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 -// } -- Gitblit v1.8.0