From eb47f1055b958438069fe6a96867835843ca595e Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期四, 19 十二月 2019 15:15:50 +0800
Subject: [PATCH] dupate

---
 gohumantrack/gohumantrack.go |   50 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/gohumantrack/gohumantrack.go b/gohumantrack/gohumantrack.go
index ffed316..1723e84 100644
--- a/gohumantrack/gohumantrack.go
+++ b/gohumantrack/gohumantrack.go
@@ -23,7 +23,6 @@
 	return imgs;
 }
 int fill_images(void *imgs, const int size, const int index, void *data, const int w, const int h, const int c){
-	if(!imgs || !data || size <= index) return -1;
 	c_img *images = (c_img*)imgs;
 	images[index].data_ = (unsigned char*)data;
 	images[index].w_ = w;
@@ -39,18 +38,17 @@
 	}
 	return ret;
 }
-void *process(void *handle, void *imgs, const int size, void *result){
+int process(void *handle, void *imgs, const int size, void *result){
 	c_img *images = (c_img*)imgs;
 	c_fgRet *res = (c_fgRet *)result;
-	int ret = c_human_tracker_process(handle, images, size, res);
-	if (ret != 0)
-		return NULL;
-	return res;
+	return c_human_tracker_process(handle, images, size, res);
 }
 */
 import "C"
 import (
+	"analysis/logo"
 	"errors"
+	"fmt"
 	"math"
 	"unsafe"
 )
@@ -98,7 +96,7 @@
 // HumanTracker struct
 type HumanTracker struct {
 	handle    unsafe.Pointer
-	result 	  unsafe.Pointer
+	result    unsafe.Pointer
 	batchSize int
 }
 
@@ -155,8 +153,8 @@
 	}
 
 	cRet := C.process(h.handle, cImgs, C.int(h.batchSize), h.result)
-	if cRet == nil {
-		return nil, errors.New("create C results error")
+	if cRet != 0 {
+		return nil, fmt.Errorf("process error: %d", int(cRet))
 	}
 
 	var result []FgResult
@@ -169,6 +167,40 @@
 	return result, nil
 }
 
+// ProcessImagePointer process
+func (h *HumanTracker) ProcessImagePointer(imgs []*ImageHumanTracker) ([]FgResult, error) {
+	if len(imgs) != h.batchSize {
+		return nil, errors.New("input images count doesn't equalize to batchsize")
+	}
+	cImgs := C.create_batch_image(C.int(h.batchSize))
+	if cImgs == nil {
+		return nil, errors.New("create C images error")
+	}
+	defer C.free(cImgs)
+	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), nil, 0, 0, 0)
+		} 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))
+		}
+	}
+
+	cRet := C.process(h.handle, cImgs, C.int(h.batchSize), h.result)
+	if cRet != 0 {
+		return nil, fmt.Errorf("process image pointer error: %d", int(cRet))
+	}
+
+	var result []FgResult
+	p := uintptr(h.result)
+	for i := 0; i < h.batchSize; i++ {
+		j := *(*FgResult)(unsafe.Pointer(p))
+		result = append(result, j)
+		p += unsafe.Sizeof(j)
+	}
+	return result, nil
+}
+
 // FFSimilarity similarity
 func FFSimilarity(feaA, feaB [128]float32) float64 {
 	var norm1, norm2 float64

--
Gitblit v1.8.0