From eb19ddaebdf451cee76dc31082a3194a5f9b50ac Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 10 十二月 2019 15:35:51 +0800
Subject: [PATCH] update

---
 goyolo.go |   74 +++++++++++++++++++++++++++++--------
 1 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/goyolo.go b/goyolo.go
index 4d90dc0..7ed2d15 100644
--- a/goyolo.go
+++ b/goyolo.go
@@ -68,16 +68,8 @@
 // RatioInterTrack 璺熻釜鍒ゆ柇閲嶅彔闃堝��
 const RatioInterTrack = 50 //璺熻釜鍒ゆ柇閲嶅彔闃堝��
 
-// SDKImage sdk image
-type SDKImage struct {
-	Data    []byte
-	Width   int
-	Height  int
-	Channel int
-}
-
-// NewYolo init yolo sdk
-func NewYolo(fc, fw, fn string, gi int) *YoloHandle {
+// NewSDK init yolo sdk
+func NewSDK(fc, fw, fn string, gi int) interface{} {
 
 	c := C.CString(fc)
 	defer C.free(unsafe.Pointer(c))
@@ -96,7 +88,8 @@
 }
 
 // Free free
-func Free(y *YoloHandle) {
+func Free(i interface{}) {
+	y := i.(*YoloHandle)
 	if y != nil {
 		if y.handle != nil {
 			C.release(y.handle)
@@ -134,7 +127,8 @@
 }
 
 // YoloObjName obj name by type
-func YoloObjName(y *YoloHandle, typ int) string {
+func YoloObjName(i interface{}, typ int) string {
+	y := i.(*YoloHandle)
 	p := C.obj_name_by_type(y.handle, C.int(typ))
 
 	return C.GoString(p)
@@ -223,6 +217,45 @@
 	return allObjs, newObjs
 }
 
+// Run yolo detect   (鍙瘑鍒汉)
+func Run(i interface{}, id string, data []byte, w, h, c int, thrsh float32, umns int) ([]byte, int) {
+	if data == nil || w <= 0 || h <= 0 {
+		return nil, 0
+	}
+	y := i.(*YoloHandle)
+
+	channel := c
+	if channel == 0 {
+		channel = 3
+	}
+
+	v, ok := y.tracker[id]
+	if !ok {
+		i := &trackInfo{}
+		y.tracker[id] = i
+		v = i
+	}
+	whole, _ := YoloDetectTrack2(y, v.lastTrackObjs, &v.lastTrackID, data, w, h, channel, thrsh, umns)
+	y.tracker[id].lastTrackObjs = whole
+	y.tracker[id].lastTrackID = v.lastTrackID
+
+	var dWhole []byte
+	var err error
+	if len(whole) > 0 {
+
+		infos := convert2ProtoYoloTrack(whole, 1.0, 1.0)
+		p := protomsg.ParamYoloObj{Infos: infos}
+
+		dWhole, err = proto.Marshal(&p)
+		if err != nil {
+			fmt.Println("ydetect track marshal proto yolo obj error", err)
+			dWhole = nil
+		}
+	}
+
+	return dWhole, len(whole)
+}
+
 func convert2ProtoYoloTrack(obj []CObjTrackInfo, fx, fy float64) []*protomsg.ObjInfo {
 	ret := []*protomsg.ObjInfo{}
 
@@ -252,8 +285,17 @@
 	return ret
 }
 
-// YoloDetectTrack yolo detect   (鍙瘑鍒汉)
-func YoloDetectTrack(y *YoloHandle, id string, data []byte, w, h, c int, thrsh float32, umns int) ([]byte, []byte) {
+// Run2 yolo detect   (鍙瘑鍒汉)
+func Run2(i interface{}, id string, data []byte, w, h, c int, thrsh float32, umns int) ([]byte, int, []byte, int) {
+	if data == nil || w <= 0 || h <= 0 {
+		return nil, 0, nil, 0
+	}
+	y := i.(*YoloHandle)
+
+	channel := c
+	if channel == 0 {
+		channel = 3
+	}
 
 	v, ok := y.tracker[id]
 	if !ok {
@@ -261,7 +303,7 @@
 		y.tracker[id] = i
 		v = i
 	}
-	whole, recent := YoloDetectTrack2(y, v.lastTrackObjs, &v.lastTrackID, data, w, h, c, thrsh, umns)
+	whole, recent := YoloDetectTrack2(y, v.lastTrackObjs, &v.lastTrackID, data, w, h, channel, thrsh, umns)
 	y.tracker[id].lastTrackObjs = whole
 	y.tracker[id].lastTrackID = v.lastTrackID
 
@@ -281,5 +323,5 @@
 	if len(recent) > 0 {
 		dRecent = nil
 	}
-	return dWhole, dRecent
+	return dWhole, len(whole), dRecent, len(recent)
 }

--
Gitblit v1.8.0