From 114ee011af25b727409541dbab8c7ac85f266c0c Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期四, 19 十二月 2019 15:08:02 +0800
Subject: [PATCH] update
---
work/sdk/plateIDdetect.go | 91 +++++++++++++++++++--------------------------
1 files changed, 39 insertions(+), 52 deletions(-)
diff --git a/work/sdk/plateIDdetect.go b/work/sdk/plateIDdetect.go
index 0fce158..520d66a 100644
--- a/work/sdk/plateIDdetect.go
+++ b/work/sdk/plateIDdetect.go
@@ -4,7 +4,6 @@
"analysis/logo"
"analysis/work"
"context"
- "time"
"analysis/gosdk"
)
@@ -15,6 +14,7 @@
cfgCloud *gosdk.CPlateIDCloudCfg
licSrvPath string
modelPath string
+ list *LockList
fn func(*gosdk.SDKImage, *gosdk.CRECT, int, int, *work.MsgRS, chan<- work.MsgRS)
}
@@ -31,6 +31,7 @@
return &PlateIDDetector{
licSrvPath: licSrv,
modelPath: model,
+ list: NewLockList(6),
fn: vehicle,
}
}
@@ -46,6 +47,7 @@
cfgCloud: nil,
licSrvPath: licSrv,
modelPath: "",
+ list: NewLockList(6),
fn: eparking,
}
@@ -60,10 +62,21 @@
cfgCloud: cfg,
licSrvPath: licSrv,
modelPath: model,
+ list: NewLockList(6),
fn: cloud,
}
}
return nil
+}
+
+func (d *PlateIDDetector) Free() {
+ if d.config != nil {
+ gosdk.FreePlateIdDetector()
+ } else if d.cfgCloud != nil {
+ gosdk.FreePlateIDCloudSDKDetector()
+ } else {
+ gosdk.FreeVehicleITSDetector()
+ }
}
// Init impl
@@ -89,59 +102,33 @@
return true
}
+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)
+ return
+ }
+
+ imgW, imgH := int(i.Width), int(i.Height)
+ img := gosdk.SDKImage{Data: i.Data, Width: imgW, Height: imgH}
+
+ rcDetect := gosdk.CRECT{
+ Left: 0,
+ Top: 0,
+ Right: (int32)(imgW),
+ Bottom: (int32)(imgH),
+ }
+
+ mW, mH := 4096, 2160
+ if d.config != nil {
+ mW, mH = int(d.config.MaxImageWidth), int(d.config.MaxImageHeight)
+ }
+ d.fn(&img, &rcDetect, mW, mH, &rMsg, out)
+}
+
// 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
- }
-
- 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)
- img := gosdk.SDKImage{Data: i.Data, Width: imgW, Height: imgH}
-
- rcDetect := gosdk.CRECT{
- Left: 0,
- Top: 0,
- Right: (int32)(imgW),
- Bottom: (int32)(imgH),
- }
-
- mW, mH := 4096, 2160
- if d.config != nil {
- 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()
- }
-
- }
- }
+ 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) {
--
Gitblit v1.8.0