From 747334f8411a7ef22aa7e67cfa63d17c486b9cce Mon Sep 17 00:00:00 2001 From: Endre Simo Date: Wed, 6 Feb 2019 16:18:04 +0200 Subject: [PATCH] remove if condition --- examples/python/demo.py | 2 +- examples/python/pigo.go | 46 ++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/examples/python/demo.py b/examples/python/demo.py index be7b2f3..93a86bb 100644 --- a/examples/python/demo.py +++ b/examples/python/demo.py @@ -21,7 +21,7 @@ class GoPixelSlice(Structure): # Obtain the camera pixels and transfer them to Go trough Ctypes. def process_frame(pixs): - dets = numpy.zeros(3*MAX_NDETS, dtype=numpy.float32) + dets = numpy.zeros(3 * MAX_NDETS, dtype=numpy.float32) pixels = cast((c_ubyte * len(pixs))(*pixs), POINTER(c_ubyte)) # call FindFaces diff --git a/examples/python/pigo.go b/examples/python/pigo.go index 6a267f8..cdddea1 100644 --- a/examples/python/pigo.go +++ b/examples/python/pigo.go @@ -34,38 +34,36 @@ func FindFaces(pixels []uint8) uintptr { } } - if len(result) > 0 { - // Since we cannot transfer a 2d array trough an array pointer - // we have to transform it into 1d array. - go func() { - det := make([]int, 0, len(result)) - for _, v := range result { - det = append(det, v...) - } - fmt.Println(det) - // Include as a first slice element the number of detected faces. - // We need to transfer this value in order to define the Python array buffer length. - det = append([]int{len(result), 0, 0}, det...) + // Since in Go we cannot transfer a 2d array trough an array pointer + // we have to transform it into 1d array. + go func() { + det := make([]int, 0, len(result)) + for _, v := range result { + det = append(det, v...) + } + fmt.Println(det) + // Include as a first slice element the number of detected faces. + // We need to transfer this value in order to define the Python array buffer length. + det = append([]int{len(result), 0, 0}, det...) - // Convert the slice into an array pointer. - s := *(*[]int)(unsafe.Pointer(&det)) - p := uintptr(unsafe.Pointer(&s[0])) + // Convert the slice into an array pointer. + s := *(*[]int)(unsafe.Pointer(&det)) + p := uintptr(unsafe.Pointer(&s[0])) - // Ensure `det` is not freed up by GC prematurely. - runtime.KeepAlive(det) - // return the pointer address - pointCh <- p - }() - return <-pointCh - } - return 0 + // Ensure `det` is not freed up by GC prematurely. + runtime.KeepAlive(det) + + // return the pointer address + pointCh <- p + }() + return <-pointCh } // clusterDetection runs Pigo face detector core methods // and returns a cluster with the detected faces coordinates. func clusterDetection(pixels []uint8, rows, cols int) []pigo.Detection { cParams := pigo.CascadeParams{ - MinSize: 100, + MinSize: 20, MaxSize: 1000, ShiftFactor: 0.15, ScaleFactor: 1.1,