From 5e920908a12c7d7372e145f04f315e00d5540d7a Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期四, 19 十二月 2019 16:23:03 +0800
Subject: [PATCH] update

---
 gohumantrack/gohumantrack.go |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gohumantrack/gohumantrack.go b/gohumantrack/gohumantrack.go
index 7ac52ba..ac304da 100644
--- a/gohumantrack/gohumantrack.go
+++ b/gohumantrack/gohumantrack.go
@@ -22,6 +22,13 @@
 	}
 	return imgs;
 }
+
+void *create_fake_image(const int size){
+	unsigned char *img = (unsigned char*)malloc(size);
+	memset(img, 0, size);
+	return img;
+}
+
 int fill_images(void *imgs, const int size, const int index, void *data, const int w, const int h, const int c){
 	c_img *images = (c_img*)imgs;
 	images[index].data_ = (unsigned char*)data;
@@ -102,6 +109,7 @@
 	handle    unsafe.Pointer
 	result    unsafe.Pointer
 	batchSize int
+	fakeImage unsafe.Pointer
 }
 
 // NewHumanTracker new
@@ -124,6 +132,9 @@
 	}
 	if h.result != nil {
 		C.free(h.result)
+	}
+	if h.fakeImage != nil {
+		C.free(h.fakeImage)
 	}
 }
 
@@ -181,11 +192,13 @@
 		return nil, errors.New("create C images error")
 	}
 	defer C.free(cImgs)
-	fake := make([]byte, wid*hei*chn)
 	for k, v := range imgs {
 		logo.Infoln("batch~~~~~~", k, " image: ", v)
 		if v == nil {
-			C.fill_images(cImgs, C.int(h.batchSize), C.int(k), unsafe.Pointer(&fake[0]), C.int(wid), C.int(hei), C.int(chn))
+			if h.fakeImage == nil {
+				h.fakeImage = C.create_fake_image(wid * hei * chn)
+			}
+			C.fill_images(cImgs, C.int(h.batchSize), C.int(k), h.fakeImage, C.int(wid), C.int(hei), C.int(chn))
 		} else {
 			C.fill_images(cImgs, C.int(h.batchSize), C.int(k), unsafe.Pointer(&v.Data[0]), C.int(v.Width), C.int(v.Height), C.int(v.Channel))
 		}

--
Gitblit v1.8.0