From 00d07f58cd88a1e9dd13deed75ad1af3db6ebcf6 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 17 十二月 2019 16:07:01 +0800
Subject: [PATCH] udpate

---
 work/sdk/humantrack.go |  116 +++++++++++++++++++++++++--------------------------------
 1 files changed, 51 insertions(+), 65 deletions(-)

diff --git a/work/sdk/humantrack.go b/work/sdk/humantrack.go
index e84b9ff..f0edec8 100644
--- a/work/sdk/humantrack.go
+++ b/work/sdk/humantrack.go
@@ -5,7 +5,6 @@
 	"analysis/work"
 	"context"
 	"plugin"
-	"time"
 
 	"github.com/gogo/protobuf/proto"
 
@@ -20,8 +19,10 @@
 	batchSize int
 	flag      int
 
+	list *LockList
+
 	handle       interface{}
-	fnInit       func(int, int, int) interface{}
+	fnInit       func(int, int, int, func(...interface{})) interface{}
 	fnFree       func(interface{})
 	fnRun        func(interface{}, []byte, int, int, int) []sdkstruct.FgResult
 	fnProcess    func(interface{}, []sdkstruct.SDKImage) ([]sdkstruct.FgResult, error)
@@ -31,7 +32,7 @@
 
 // NewHumanTracker new
 func NewHumanTracker(gpu, batchSize, flag int) *HumanTracker {
-	soFile := "libyolo.so"
+	soFile := "libhumantrack.so"
 
 	plug, err := plugin.Open(soFile)
 	if err != nil {
@@ -51,8 +52,10 @@
 		batchSize: batchSize,
 		flag:      flag,
 
+		list: NewLockList(6),
+
 		handle:       nil,
-		fnInit:       fnInit.(func(int, int, int) interface{}),
+		fnInit:       fnInit.(func(int, int, int, func(...interface{})) interface{}),
 		fnFree:       fnFree.(func(interface{})),
 		fnRun:        fnRun.(func(interface{}, []byte, int, int, int) []sdkstruct.FgResult),
 		fnProcess:    fnProc.(func(interface{}, []sdkstruct.SDKImage) ([]sdkstruct.FgResult, error)),
@@ -71,7 +74,7 @@
 	if gpu == -1 {
 		gpu = gogpu.ValidGPU(2048)
 	}
-	h := t.fnInit(gpu, t.batchSize, t.flag)
+	h := t.fnInit(gpu, t.batchSize, t.flag, logo.Infoln)
 	logo.Infoln("HumanTrack USE GPU: ", gpu)
 
 	if h == nil {
@@ -83,69 +86,52 @@
 	return true
 }
 
+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 []sdkstruct.SDKImage
+	// img := sdkstruct.SDKImage{
+	// 	Data:    i.Data,
+	// 	Width:   imgW,
+	// 	Height:  imgH,
+	// 	Channel: 3,
+	// }
+	// images = append(images, img)
+	res := t.fnRun(t.handle, i.Data, imgW, imgH, 3)
+	if res == nil {
+		logo.Errorln("HUMAN TRACKER RUN ERROR")
+
+		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 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 YOLO 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 []sdkstruct.SDKImage
-			// img := sdkstruct.SDKImage{
-			// 	Data:    i.Data,
-			// 	Width:   imgW,
-			// 	Height:  imgH,
-			// 	Channel: 3,
-			// }
-			// images = append(images, img)
-			res := t.fnRun(t.handle, i.Data, imgW, imgH, 3)
-			if res != 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, func() { t.fnFree(t.handle) })
 }
 
 // message HumanTrack {

--
Gitblit v1.8.0