派生自 libgowrapper/face

zhangmeng
2019-12-16 a0593e3fed8739b42e594f25f8f57075601e07cb
goface.go
@@ -24,10 +24,11 @@
   extractor   bool
   propertizer bool
   tracker     bool
   fnLogger    func(...interface{})
}
// NewSDK sdk
func NewSDK() interface{} {
func NewSDK(fn func(...interface{})) interface{} {
   h := C.create_sdkface()
   if h == nil {
      return nil
@@ -39,6 +40,7 @@
      extractor:   false,
      propertizer: false,
      tracker:     false,
      fnLogger:    fn,
   }
}
@@ -50,6 +52,12 @@
   }
}
func (s *SDKFace) printLog(l ...interface{}) {
   if s.fnLogger != nil {
      s.fnLogger(l)
   }
}
// Detector detector
func Detector(i interface{}, minFaces, rollAngles, threadMax, gpu int) bool {
   s := i.(*SDKFace)
@@ -58,6 +66,7 @@
   }
   ret := C.init_detector(s.handle, C.int(minFaces), C.int(rollAngles), C.int(threadMax), C.int(gpu))
   if ret <= 0 {
      s.printLog("->face--> CREATE Detector ERROR")
      return false
   }
   s.detector = true
@@ -72,6 +81,7 @@
   }
   ret := C.init_extractor(s.handle, C.int(threadMax), C.int(gpu))
   if ret <= 0 {
      s.printLog("->face--> CREATE Extractor ERROR")
      return false
   }
   s.extractor = true
@@ -86,6 +96,7 @@
   }
   ret := C.init_propertizer(s.handle, C.int(threadMax))
   if ret <= 0 {
      s.printLog("->face--> CREATE Propertizer ERROR")
      return false
   }
   s.propertizer = true
@@ -101,6 +112,7 @@
   ret := C.init_tracker(s.handle, C.int(w), C.int(h), C.int(maxFaces), C.int(interval), C.int(sampleSize), C.int(threadMax), C.int(gpu))
   if ret <= 0 {
      s.printLog("->face--> CREATE Tracker ERROR")
      return false
   }
   s.tracker = true
@@ -133,6 +145,7 @@
   if ret > 0 {
      return CFacePosArrayToGoArray(cfpos, int(count))
   }
   s.printLog("->face--> Detect No One, Ret: ", ret)
   return nil
}
@@ -144,10 +157,11 @@
   //(void *handle, const cFacePos *pos, const void*data, const int w, const int h, const int c, const int chan, void **feat, int *featLen);
   var feat unsafe.Pointer
   var featLen C.int
   p := C.extract(s.handle, pos, unsafe.Pointer(&data[0]), C.int(w), C.int(h), C.int(c), C.int(ch), &feat, &featLen)
   if p > 0 {
   ret := C.extract(s.handle, pos, unsafe.Pointer(&data[0]), C.int(w), C.int(h), C.int(c), C.int(ch), &feat, &featLen)
   if ret > 0 {
      return C.GoBytes(feat, featLen)
   }
   s.printLog("->face--> Extract Nothing, Ret: ", ret)
   return nil
}
@@ -177,6 +191,7 @@
      C.free(thft)
      return &gothft
   }
   s.printLog("->face--> Propertize Nothing, Ret: ", ret)
   return nil
}
@@ -209,7 +224,6 @@
      //if len(faces) > 0{
      // fmt.Println("faces detected:", len(faces))
      //}
      return faces
   }
   return nil
@@ -237,12 +251,14 @@
   s := i.(*SDKFace)
   if !s.tracker {
      s.printLog("->face--> TrackerResize Failed, No Tracker Init")
      return false
   }
   ret := C.resize(s.handle, C.int(w), C.int(h), C.int(ch))
   if ret >= 0 {
   if ret == 1 {
      return true
   }
   s.printLog("->face--> TrackerResize Failed, Ret: ", ret, " SDK Channel: ", ch, " Size: ", w, "x", h)
   return false
}
@@ -263,11 +279,13 @@
      channel = 3
   }
   // if !TrackerResize(i, w, h, dchan) {
   //    return nil
   // }
   var fInfo []sdkstruct.CFaceInfo
   if s.tracker {
      fInfo = Track(s, data, w, h, c, dchan)
   }
   fInfo = Track(s, data, w, h, c, dchan)
   var faces []sdkstruct.CFaceResult
   //将sdk返回值转换成protomsg类型