From cae1319f90bfb88fdac02ed07a38396e7ca4378a Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期四, 19 十二月 2019 15:48:57 +0800 Subject: [PATCH] update --- work/sdk/humantrack.go | 94 +++++++++++++++++++++++++++++++++------------- 1 files changed, 67 insertions(+), 27 deletions(-) diff --git a/work/sdk/humantrack.go b/work/sdk/humantrack.go index dae08ae..10b069d 100644 --- a/work/sdk/humantrack.go +++ b/work/sdk/humantrack.go @@ -1,6 +1,7 @@ package sdk import ( + "analysis/goconv" "analysis/logo" "analysis/work" "context" @@ -13,6 +14,13 @@ "basic.com/valib/gogpu.git" ) +type imageWithID struct { + img *gohumantrack.ImageHumanTracker + fx float32 + fy float32 + id string +} + // HumanTracker track type HumanTracker struct { tracker *gohumantrack.HumanTracker @@ -24,7 +32,7 @@ mapCameraImageIndex map[string]int recvImageCount int index int - images []*gohumantrack.ImageHumanTracker + images []*imageWithID msgs []*work.MsgRS } @@ -36,10 +44,11 @@ flag: flag, list: NewLockList(6), - recvImageCount: 0, - index: 0, - images: make([]*gohumantrack.ImageHumanTracker, batchSize), - msgs: make([]*work.MsgRS, batchSize), + recvImageCount: 0, + index: 0, + mapCameraImageIndex: make(map[string]int), + images: make([]*imageWithID, batchSize), + msgs: make([]*work.MsgRS, batchSize), } } @@ -116,6 +125,14 @@ imgW, imgH := int(i.Width), int(i.Height) + var imgData []byte + rw, rh := 1280, 720 + fx, fy := 1.0, 1.0 + if imgW != rw || imgH != rh { + imgData = goconv.ResizeBGR(i.Data, imgW, imgH, rw, rh) + fx = (float32)(rw)/(float32)imgW + fy = (float32)(rh)/(float32)imgH + } img := gohumantrack.ImageHumanTracker{ Data: i.Data, Width: imgW, @@ -126,44 +143,44 @@ // mapCameraImageIndex map[string]int // images []gohumantrack.ImageHumanTracker - if t.mapCameraImageIndex == nil { - t.recvImageCount = 0 - t.index = 0 - - t.mapCameraImageIndex = make(map[string]int) - for i := 0; i < t.batchSize; i++ { - t.images[i] = nil - } - for i := 0; i < t.batchSize; i++ { - t.msgs[i] = nil - } - } - - t.recvImageCount++ - if i, ok := t.mapCameraImageIndex[rMsg.Msg.Cid]; ok { if i < t.batchSize { - t.images[i] = &img + t.images[i] = &imageWithID{&img, fx, fy, rMsg.Msg.Cid} t.msgs[i] = &rMsg } } else { if t.index < t.batchSize { - t.images[t.index] = &img + t.images[t.index] = &imageWithID{&img, fx, fy, rMsg.Msg.Cid} t.msgs[t.index] = &rMsg t.mapCameraImageIndex[rMsg.Msg.Cid] = t.index } t.index++ } + t.recvImageCount++ + if t.recvImageCount < t.batchSize+t.batchSize/2 { - logo.Infoln("batch~~~~~~Current Index: ", t.index) return } - res, err := t.tracker.ProcessImagePointer(t.images[:]) - t.mapCameraImageIndex = nil + for k, v := range t.mapCameraImageIndex { + logo.Infoln("batch~~~~~~Map index: ", v, " camera: ", k) + } + + var pimg []*gohumantrack.ImageHumanTracker + for k, v := range t.images[:] { + if v != nil { + pimg = append(pimg, v.img) + logo.Infoln("batch~~~~~~Image index: ", k, " camera: ", v.id, " image address: ", v.img) + } else { + pimg = append(pimg, nil) + } + } + + res, err := t.tracker.ProcessImagePointer(pimg) + t.recvImageCount = 0 if err != nil { - logo.Infoln("batch~~~~~~Track Failed: ", err) + logo.Infoln("batch~~~~~~Track Image Count: ", t.index, " Failed: ", err) ejectResult(nil, rMsg, out) return } @@ -172,7 +189,7 @@ if t.images[i] == nil { continue } - hr := convert2ProtoHumanTrackResult(res[i]) + hr := convert2ProtoHumanTrackResultWithScale(res[i], t.images[i].fx, t.images[i].fy) result := protomsg.HumanTrackResult{Result: hr} data, err := proto.Marshal(&result) if err != nil { @@ -232,3 +249,26 @@ } return res } + +func convert2ProtoHumanTrackResultWithScale(obj gohumantrack.FgResult, fx, fy float32) []*protomsg.HumanTrack { + res := []*protomsg.HumanTrack{} + for i := 0; i < int(obj.FgNum); i++ { + r := obj.Fginfo[i] + rect := protomsg.Rect{ + Left: (int32)((float32)(r.Left)/fx), + Right: (int32)((float32)(r.Right)/fy), + Top: (int32)((float32)(r.Top)/fx), + Bottom: (int32)((float32)(r.Bottom)/fy), + } + pr := &protomsg.HumanTrack{ + RcHuman: &rect, + Confidence: r.Confidence, + X: (int32)((float32)(r.X)/fx, + Y: (int32)((float32)(r.Y)/fy, + Id: r.ID, + Feature: r.Feature[:], + } + res = append(res, pr) + } + return res +} -- Gitblit v1.8.0