| | |
| | | return imgs; |
| | | } |
| | | int fill_images(void *imgs, const int size, const int index, void *data, const int w, const int h, const int c){ |
| | | if(!imgs || !data || size <= index) return -1; |
| | | c_img *images = (c_img*)imgs; |
| | | images[index].data_ = (unsigned char*)data; |
| | | images[index].w_ = w; |
| | |
| | | } |
| | | return ret; |
| | | } |
| | | void *process(void *handle, void *imgs, const int size, void *result){ |
| | | int process(void *handle, void *imgs, const int size, void *result){ |
| | | c_img *images = (c_img*)imgs; |
| | | c_fgRet *res = (c_fgRet *)result; |
| | | int ret = c_human_tracker_process(handle, images, size, res); |
| | | if (ret != 0) |
| | | return NULL; |
| | | return res; |
| | | return c_human_tracker_process(handle, images, size, res); |
| | | } |
| | | */ |
| | | import "C" |
| | | import ( |
| | | "analysis/logo" |
| | | "errors" |
| | | "fmt" |
| | | "math" |
| | |
| | | } |
| | | |
| | | cRet := C.process(h.handle, cImgs, C.int(h.batchSize), h.result) |
| | | if cRet == nil { |
| | | return nil, errors.New("create C results error") |
| | | if cRet != 0 { |
| | | return nil, fmt.Errorf("process error: %d", int(cRet)) |
| | | } |
| | | |
| | | var result []FgResult |
| | |
| | | } |
| | | defer C.free(cImgs) |
| | | for k, v := range imgs { |
| | | var ret C.int |
| | | logo.Infoln("batch~~~~~~", k, " image: ", v) |
| | | if v == nil { |
| | | ret = C.fill_images(cImgs, C.int(h.batchSize), C.int(k), nil, 0, 0, 0) |
| | | C.fill_images(cImgs, C.int(h.batchSize), C.int(k), nil, 0, 0, 0) |
| | | } else { |
| | | ret = C.fill_images(cImgs, C.int(h.batchSize), C.int(k), unsafe.Pointer(&v.Data[0]), C.int(v.Width), C.int(v.Height), C.int(v.Channel)) |
| | | } |
| | | if int(ret) != k { |
| | | return nil, fmt.Errorf("fill C images error: %d", int(ret)) |
| | | C.fill_images(cImgs, C.int(h.batchSize), C.int(k), unsafe.Pointer(&v.Data[0]), C.int(v.Width), C.int(v.Height), C.int(v.Channel)) |
| | | } |
| | | } |
| | | |
| | | cRet := C.process(h.handle, cImgs, C.int(h.batchSize), h.result) |
| | | if cRet == nil { |
| | | return nil, errors.New("create C results error") |
| | | if cRet != 0 { |
| | | return nil, fmt.Errorf("process image pointer error: %d", int(cRet)) |
| | | } |
| | | |
| | | var result []FgResult |
| | | p := uintptr(cRet) |
| | | p := uintptr(h.result) |
| | | for i := 0; i < h.batchSize; i++ { |
| | | j := *(*FgResult)(unsafe.Pointer(p)) |
| | | result = append(result, j) |