remove if condition

This commit is contained in:
Endre Simo
2019-02-06 16:18:04 +02:00
parent 57f26c8d4a
commit 747334f841
2 changed files with 23 additions and 25 deletions

View File

@@ -21,7 +21,7 @@ class GoPixelSlice(Structure):
# Obtain the camera pixels and transfer them to Go trough Ctypes. # Obtain the camera pixels and transfer them to Go trough Ctypes.
def process_frame(pixs): 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)) pixels = cast((c_ubyte * len(pixs))(*pixs), POINTER(c_ubyte))
# call FindFaces # call FindFaces

View File

@@ -34,38 +34,36 @@ func FindFaces(pixels []uint8) uintptr {
} }
} }
if len(result) > 0 { // Since in Go we cannot transfer a 2d array trough an array pointer
// Since we cannot transfer a 2d array trough an array pointer // we have to transform it into 1d array.
// we have to transform it into 1d array. go func() {
go func() { det := make([]int, 0, len(result))
det := make([]int, 0, len(result)) for _, v := range result {
for _, v := range result { det = append(det, v...)
det = append(det, v...) }
} fmt.Println(det)
fmt.Println(det) // Include as a first slice element the number of detected faces.
// 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.
// We need to transfer this value in order to define the Python array buffer length. det = append([]int{len(result), 0, 0}, det...)
det = append([]int{len(result), 0, 0}, det...)
// Convert the slice into an array pointer. // Convert the slice into an array pointer.
s := *(*[]int)(unsafe.Pointer(&det)) s := *(*[]int)(unsafe.Pointer(&det))
p := uintptr(unsafe.Pointer(&s[0])) p := uintptr(unsafe.Pointer(&s[0]))
// Ensure `det` is not freed up by GC prematurely. // Ensure `det` is not freed up by GC prematurely.
runtime.KeepAlive(det) runtime.KeepAlive(det)
// return the pointer address
pointCh <- p // return the pointer address
}() pointCh <- p
return <-pointCh }()
} return <-pointCh
return 0
} }
// clusterDetection runs Pigo face detector core methods // clusterDetection runs Pigo face detector core methods
// and returns a cluster with the detected faces coordinates. // and returns a cluster with the detected faces coordinates.
func clusterDetection(pixels []uint8, rows, cols int) []pigo.Detection { func clusterDetection(pixels []uint8, rows, cols int) []pigo.Detection {
cParams := pigo.CascadeParams{ cParams := pigo.CascadeParams{
MinSize: 100, MinSize: 20,
MaxSize: 1000, MaxSize: 1000,
ShiftFactor: 0.15, ShiftFactor: 0.15,
ScaleFactor: 1.1, ScaleFactor: 1.1,