| | |
| | | // HumanTracker struct |
| | | type HumanTracker struct { |
| | | handle unsafe.Pointer |
| | | result unsafe.Pointer |
| | | result unsafe.Pointer |
| | | batchSize int |
| | | } |
| | | |
| | |
| | | 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 { |
| | | ret := 0 |
| | | if v == nil { |
| | | ret = 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, errors.New("fill C images error") |
| | | } |
| | | } |
| | | |
| | | cRet := C.process(h.handle, cImgs, C.int(h.batchSize), h.result) |
| | | if cRet == nil { |
| | | return nil, errors.New("create C results error") |
| | | } |
| | | |
| | | var result []FgResult |
| | | p := uintptr(cRet) |
| | | 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 |