mirror of
https://github.com/esimov/pigo.git
synced 2025-10-07 00:52:49 +08:00
Using goroutines ans channels for object detection
This commit is contained in:
@@ -23,7 +23,8 @@ func main() {}
|
||||
|
||||
//export FindFaces
|
||||
func FindFaces(pixels []uint8) uintptr {
|
||||
if len(pixels) > 0 {
|
||||
pointCh := make(chan uintptr)
|
||||
|
||||
dets := clusterDetection(pixels, 480, 640)
|
||||
result := make([][]int, len(dets))
|
||||
|
||||
@@ -32,28 +33,30 @@ func FindFaces(pixels []uint8) uintptr {
|
||||
result[i] = append(result[i], dets[i].Row, dets[i].Col, dets[i].Scale)
|
||||
}
|
||||
}
|
||||
fmt.Println(dets)
|
||||
|
||||
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...)
|
||||
fmt.Println(det)
|
||||
|
||||
// Convert the slice into an array pointer.
|
||||
s := *(*[]int)(unsafe.Pointer(&det))
|
||||
p := uintptr(unsafe.Pointer(&s[0]))
|
||||
|
||||
runtime.KeepAlive(result)
|
||||
// Ensure `det` is not freed by GC.
|
||||
runtime.KeepAlive(det)
|
||||
// return the pointer address
|
||||
return p
|
||||
}
|
||||
pointCh <- p
|
||||
}()
|
||||
return <-pointCh
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user