mirror of
https://github.com/LdDl/go-darknet.git
synced 2025-09-27 12:02:19 +08:00

* Use `C.CString()` instead of `C._GoStringPtr()`. - Seems like sometimes the pointer returned by `C._GoStringPtr()` could already be freed, while work is being done in C code that uses the pointer. Using `C.CString()` ensures the C string's lifetime. * Remove own implementation of `free_network()`; Darknet actually does have its own! * Changed some field names of `YOLONetwork` to make them look more consistent.
29 lines
549 B
Go
29 lines
549 B
Go
package darknet
|
|
|
|
// #include <stdlib.h>
|
|
// #include "class_name.h"
|
|
import "C"
|
|
import "unsafe"
|
|
|
|
func freeClassNames(names **C.char) {
|
|
C.free_class_names(names)
|
|
}
|
|
|
|
func loadClassNames(dataConfigFile string) **C.char {
|
|
d := C.CString(dataConfigFile)
|
|
defer C.free(unsafe.Pointer(d))
|
|
|
|
return C.read_class_names(d)
|
|
}
|
|
|
|
func makeClassNames(names **C.char, classes int) []string {
|
|
out := make([]string, classes)
|
|
for i := 0; i < classes; i++ {
|
|
n := C.get_class_name(names, C.int(i), C.int(classes))
|
|
s := C.GoString(n)
|
|
out[i] = s
|
|
}
|
|
|
|
return out
|
|
}
|