派生自 libgowrapper/yolo

zhangmeng
2019-12-10 eb19ddaebdf451cee76dc31082a3194a5f9b50ac
goyolo.go
@@ -68,8 +68,8 @@
// RatioInterTrack 跟踪判断重叠阈值
const RatioInterTrack = 50 //跟踪判断重叠阈值
// 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))
@@ -88,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)
@@ -126,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)
@@ -215,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{}
@@ -244,11 +285,13 @@
   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, nil
      return nil, 0, nil, 0
   }
   y := i.(*YoloHandle)
   channel := c
   if channel == 0 {
      channel = 3
@@ -280,5 +323,5 @@
   if len(recent) > 0 {
      dRecent = nil
   }
   return dWhole, dRecent
   return dWhole, len(whole), dRecent, len(recent)
}