From d8d2bc7b4cf8e4a1f2b2a325d2ca02f0eb409d9c Mon Sep 17 00:00:00 2001
From: zhangmeng <zhangmeng@aiotlink.com>
Date: 星期四, 19 十二月 2019 16:25:24 +0800
Subject: [PATCH] up

---
 work/sdk/humantrack.go |   48 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/work/sdk/humantrack.go b/work/sdk/humantrack.go
index 2700a05..46ad033 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"
@@ -15,6 +16,8 @@
 
 type imageWithID struct {
 	img *gohumantrack.ImageHumanTracker
+	fx  float64
+	fy  float64
 	id  string
 }
 
@@ -122,10 +125,18 @@
 
 	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 = (float64)(rw) / (float64)(imgW)
+		fy = (float64)(rh) / (float64)(imgH)
+	}
 	img := gohumantrack.ImageHumanTracker{
-		Data:    i.Data,
-		Width:   imgW,
-		Height:  imgH,
+		Data:    imgData,
+		Width:   rw,
+		Height:  rh,
 		Channel: 3,
 	}
 
@@ -134,12 +145,12 @@
 
 	if i, ok := t.mapCameraImageIndex[rMsg.Msg.Cid]; ok {
 		if i < t.batchSize {
-			t.images[i] = &imageWithID{&img, rMsg.Msg.Cid}
+			t.images[i] = &imageWithID{&img, fx, fy, rMsg.Msg.Cid}
 			t.msgs[i] = &rMsg
 		}
 	} else {
 		if t.index < t.batchSize {
-			t.images[t.index] = &imageWithID{&img, rMsg.Msg.Cid}
+			t.images[t.index] = &imageWithID{&img, fx, fy, rMsg.Msg.Cid}
 			t.msgs[t.index] = &rMsg
 			t.mapCameraImageIndex[rMsg.Msg.Cid] = t.index
 		}
@@ -165,7 +176,7 @@
 		}
 	}
 
-	res, err := t.tracker.ProcessImagePointer(pimg)
+	res, err := t.tracker.ProcessImagePointer(pimg, rw, rh, 3)
 	t.recvImageCount = 0
 
 	if err != nil {
@@ -178,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 {
@@ -238,3 +249,26 @@
 	}
 	return res
 }
+
+func convert2ProtoHumanTrackResultWithScale(obj gohumantrack.FgResult, fx, fy float64) []*protomsg.HumanTrack {
+	res := []*protomsg.HumanTrack{}
+	for i := 0; i < int(obj.FgNum); i++ {
+		r := obj.Fginfo[i]
+		rect := protomsg.Rect{
+			Left:   (int32)((float64)(r.Left) / fx),
+			Right:  (int32)((float64)(r.Right) / fy),
+			Top:    (int32)((float64)(r.Top) / fx),
+			Bottom: (int32)((float64)(r.Bottom) / fy),
+		}
+		pr := &protomsg.HumanTrack{
+			RcHuman:    &rect,
+			Confidence: r.Confidence,
+			X:          (int32)((float64)(r.X) / fx),
+			Y:          (int32)((float64)(r.Y) / fy),
+			Id:         r.ID,
+			Feature:    r.Feature[:],
+		}
+		res = append(res, pr)
+	}
+	return res
+}

--
Gitblit v1.8.0