package main /* #cgo CFLAGS: -I${SRCDIR}/sdk/include -I${SRCDIR}/thirdparty/include/opencv4 -I${SRCDIR}/sdk/include/torch/csrc/api/include -I${SRCDIR}/csrc -w -g #cgo CXXFLAGS: -I${SRCDIR}/sdk/include -I${SRCDIR}/thirdparty/include/opencv4 -I${SRCDIR}/sdk/include/torch/csrc/api/include -I${SRCDIR}/csrc -w -g -std=c++11 #cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/sdk/lib #cgo LDFLAGS: -L${SRCDIR}/sdk/lib -ltorch -lc10 -lc10_cuda -lcudart -lgomp -lnvToolsExt #cgo LDFLAGS: -L${SRCDIR}/thirdparty/lib -lopencv_core -lopencv_imgproc #cgo LDFLAGS: -ldl -lpthread #include #include "creid.h" float get_val(float *data, int index){ return data[index]; } */ import "C" import "unsafe" // ReID id type ReID struct { handle unsafe.Pointer } // NewSDK new reid func NewSDK(gpu int, module string) *ReID { cmodule := C.CString(module) defer C.free(unsafe.Pointer(cmodule)) h := C.create_reid(C.int(gpu), cmodule) return &ReID{h} } // Free free func (r *ReID) Free() { } // Extract extract // func (r *ReID) Extract(img []byte) []float32 { // var fSize C.int // cfeat := C.extract(r.handle, (*C.uchar)(unsafe.Pointer(&img[0])), &fSize) // if cfeat == nil { // return nil // } // ret := make([]float32, 0, fSize) // for i := 0; i < int(fSize); i++ { // r := C.get_val(cfeat, C.int(i)) // ret = append(ret, float32(r)) // } // C.free(unsafe.Pointer(cfeat)) // return ret // } // Extract2 extract func (r *ReID) Extract2(img unsafe.Pointer, w, h, c int) []float32 { var fSize C.int cfeat := C.extract(r.handle, (*C.uchar)(img), C.int(w), C.int(h), C.int(c), &fSize) if cfeat == nil { return nil } ret := make([]float32, 0, fSize) for i := 0; i < int(fSize); i++ { r := C.get_val(cfeat, C.int(i)) ret = append(ret, float32(r)) } C.free(unsafe.Pointer(cfeat)) return ret } // Compare compare func (r *ReID) Compare(feat1, feat2 []float32) float32 { p := C.compare(r.handle, (*C.float)(unsafe.Pointer(&feat1)), (*C.float)(unsafe.Pointer(&feat2))) return float32(p) }