From d78b0016f7b96f486fd4af84e889d541c3dba0eb Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 17 十二月 2019 10:33:20 +0800
Subject: [PATCH] udpate

---
 work/sdk/humantrack.go |  126 ++++++++++++++++++++---------------------
 1 files changed, 62 insertions(+), 64 deletions(-)

diff --git a/work/sdk/humantrack.go b/work/sdk/humantrack.go
index e8a82a9..99e9de0 100644
--- a/work/sdk/humantrack.go
+++ b/work/sdk/humantrack.go
@@ -4,13 +4,13 @@
 	"analysis/logo"
 	"analysis/work"
 	"context"
-	"time"
 
 	"github.com/gogo/protobuf/proto"
 
 	"analysis/gohumantrack"
 
 	"basic.com/pubsub/protomsg.git"
+	"basic.com/valib/gogpu.git"
 )
 
 // HumanTracker track
@@ -19,6 +19,7 @@
 	gpu       int
 	batchSize int
 	flag      int
+	list      *LockList
 }
 
 // NewHumanTracker new
@@ -27,6 +28,14 @@
 		gpu:       gpu,
 		batchSize: batchSize,
 		flag:      flag,
+		list:      NewLockList(6),
+	}
+}
+
+// Free free
+func (t *HumanTracker) Free() {
+	if t.tracker != nil {
+		t.tracker.Free()
 	}
 }
 
@@ -36,74 +45,63 @@
 		logo.Errorln("ONLY SUPPORT BATCH SIZE = 1")
 		return false
 	}
+	gpu := t.gpu
 
-	t.tracker = gohumantrack.NewHumanTracker(t.gpu, t.batchSize, t.flag)
-	return true
+	if gpu == -1 {
+		gpu = gogpu.ValidGPU(2048)
+	}
+	logo.Infof("start gpu %d, batch %d, flag %d\n", gpu, t.batchSize, t.flag)
+	t.tracker = gohumantrack.NewHumanTracker(gpu, t.batchSize, t.flag)
+	if t.tracker != nil {
+		logo.Infoln("Start Success")
+		return true
+	}
+	logo.Infoln("Start Failed")
+	return false
+}
+
+func (t *HumanTracker) track(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)
+
+	var images []gohumantrack.ImageHumanTracker
+	img := gohumantrack.ImageHumanTracker{
+		Data:    i.Data,
+		Width:   imgW,
+		Height:  imgH,
+		Channel: 3,
+	}
+	images = append(images, img)
+	res, err := t.tracker.Process(images)
+	if err != nil {
+		ejectResult(nil, rMsg, out)
+		return
+	}
+
+	hr := convert2ProtoHumanTrackResult(res)
+	result := protomsg.HumanTrackResult{Result: hr[0]}
+	data, err := proto.Marshal(&result)
+	if err != nil {
+		logo.Errorln("HUMAN TRACKER 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, " Human Track COUNT: ", len(hr[0]))
+
 }
 
 // Run impl
 func (t *HumanTracker) 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)
-
-			var images []gohumantrack.ImageHumanTracker
-			img := gohumantrack.ImageHumanTracker{
-				Data:    i.Data,
-				Width:   imgW,
-				Height:  imgH,
-				Channel: 3,
-			}
-			images = append(images, img)
-			res, err := t.tracker.Process(images)
-			if err != nil {
-				ejectResult(nil, rMsg, out)
-				continue
-			}
-
-			hr := convert2ProtoHumanTrackResult(res)
-			result := protomsg.HumanTrackResult{Result: hr[0]}
-			data, err := proto.Marshal(&result)
-			if err != nil {
-				logo.Errorln("HUMAN TRACKER MARSHAL PROTO PLATE IDS ERROR", err)
-				data = nil
-			}
-			ejectResult(data, rMsg, out)
-
-			/////////////////////////////////////
-			sc++
-			if sc == 25 {
-				logo.Infoln("HUMAN TRACKER RUN 25 FRAME USE TIME: ", time.Since(tm))
-				sc = 0
-				tm = time.Now()
-			}
-
-			if time.Since(tm) > time.Second {
-				logo.Infof("HUMAN TRACKER RUN %d FRAME USE TIME: %v", sc, time.Since(tm))
-				sc = 0
-				tm = time.Now()
-			}
-
-		}
-	}
+	FlowSimple(ctx, in, out, typ, t.list.Push, t.list.Pop, t.track, t.Free)
 }
 
 // message HumanTrack {

--
Gitblit v1.8.0