Video Analysis底层库拆分,sdk的go封装
zhangmeng
2019-07-15 76f25eb0e46494b7f564e704f422002331a969a5
gosdk.go
@@ -17,11 +17,12 @@
// YoloHandle wrap C
type YoloHandle struct {
   handle C.YoloHandle
   handle       C.YoloHandle
   LastYoloObjs []CObjTrackInfo //yolo跟踪的上一帧信息
   LastTrackID uint64       //yolo 被使用的ID
   LastTrackID  uint64          //yolo 被使用的ID
}
const RatioInterTrack = 50       //跟踪判断重叠阈值
const RatioInterTrack = 50 //跟踪判断重叠阈值
// SDKImage sdk image
type SDKImage struct {
@@ -43,7 +44,7 @@
   g := C.int(gi)
   p := C.c_api_yolo_init(c, w, n, g)
   return &YoloHandle{handle:p}
   return &YoloHandle{handle: p}
}
// InitFaceDetector init face detector
@@ -362,3 +363,45 @@
   return allObjs, newObjs
}
// YoloDetectTrack2 yolo detect   (只识别人)
func YoloDetectTrack2(handle *YoloHandle, LastYoloObjs []CObjTrackInfo, LastTrackID *uint64, img SDKImage, thrsh float32, umns int) (allObjs []CObjTrackInfo, newObjs []CObjTrackInfo) {
   var tmp CObjTrackInfo
   //LastYoloObjs
   detectObjs := YoloDetect(handle, img, thrsh, umns)
   for _, vLast := range LastYoloObjs {
      for i := 0; i < len(detectObjs); i++ {
         //fmt.Println("vNew.Typ:", vNew.Typ)
         if vLast.ObjInfo.Typ == detectObjs[i].Typ { //同一类别,比如都是人体
            ratio := countInterAreaOfTwoRect(vLast.ObjInfo.RcObj, detectObjs[i].RcObj)
            if ratio >= RatioInterTrack {
               //update LastYoloObjs
               vLast.ObjInfo.RcObj = detectObjs[i].RcObj
               vLast.ObjInfo.Prob = detectObjs[i].Prob
               allObjs = append(allObjs, vLast)
               detectObjs = append(detectObjs[:i], detectObjs[i+1:]...) //从检测目标里删除已经查到的跟踪目标
               i--
               break //上一帧跟踪的目标已经找到,无需往下处理其他检测目标
            }
         }
      }
   }
   //处理新出现的目标
   id := *LastTrackID
   if len(detectObjs) > 0 {
      for _, vAdd := range detectObjs {
         tmp.ObjInfo = vAdd
         tmp.ID = id
         id++
         allObjs = append(allObjs, tmp)
         newObjs = append(newObjs, tmp)
      }
   }
   *LastTrackID = id
   return allObjs, newObjs
}