| | |
| | | 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" |
| | | "unsafe" |
| | | ) |
| | |
| | | // HumanTracker struct |
| | | type HumanTracker struct { |
| | | handle unsafe.Pointer |
| | | result unsafe.Pointer |
| | | result unsafe.Pointer |
| | | batchSize int |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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 |
| | |
| | | return result, nil |
| | | } |
| | | |
| | | // ProcessImagePointer process |
| | | func (h *HumanTracker) ProcessImagePointer(imgs []*ImageHumanTracker) ([]FgResult, error) { |
| | | if len(imgs) != h.batchSize { |
| | | return nil, errors.New("input images count doesn't equalize to batchsize") |
| | | } |
| | | cImgs := C.create_batch_image(C.int(h.batchSize)) |
| | | if cImgs == nil { |
| | | return nil, errors.New("create C images error") |
| | | } |
| | | defer C.free(cImgs) |
| | | for k, v := range imgs { |
| | | logo.Infoln("batch~~~~~~", k, " image: ", v) |
| | | if v == nil { |
| | | C.fill_images(cImgs, C.int(h.batchSize), C.int(k), nil, 0, 0, 0) |
| | | } else { |
| | | 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 != 0 { |
| | | return nil, fmt.Errorf("process image pointer error: %d", int(cRet)) |
| | | } |
| | | |
| | | var result []FgResult |
| | | p := uintptr(h.result) |
| | | for i := 0; i < h.batchSize; i++ { |
| | | j := *(*FgResult)(unsafe.Pointer(p)) |
| | | result = append(result, j) |
| | | p += unsafe.Sizeof(j) |
| | | } |
| | | return result, nil |
| | | } |
| | | |
| | | // FFSimilarity similarity |
| | | func FFSimilarity(feaA, feaB [128]float32) float64 { |
| | | var norm1, norm2 float64 |