| | |
| | | package main |
| | | |
| | | import ( |
| | | "bufio" |
| | | "context" |
| | | "fmt" |
| | | "io/ioutil" |
| | | "os" |
| | | "unsafe" |
| | | |
| | | "basic.com/libgowrapper/sdkhelper.git" |
| | | "basic.com/valib/gogpu.git" |
| | | |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/godraw.git" |
| | | |
| | | "basic.com/valib/deliver.git" |
| | | "github.com/gogo/protobuf/proto" |
| | |
| | | |
| | | type reid struct { |
| | | handle *ReID |
| | | list *sdkhelper.LockList |
| | | fnLogger func(...interface{}) |
| | | |
| | | gpu int |
| | | ipc string |
| | | } |
| | | |
| | |
| | | |
| | | gpuM := sdkhelper.Atoi(cfg.Param[sGPU]) |
| | | |
| | | rGPU := 0 |
| | | rGPU := gpu |
| | | |
| | | if rGPU == -1 { |
| | | rGPU = gogpu.ValidGPU(gpuM + 512) |
| | | } |
| | | if rGPU == -1 { |
| | | fn("Reid SDK Create Error When Find GPU") |
| | | return nil |
| | | } |
| | | |
| | | rGPU = 0 |
| | | |
| | | handle := NewSDK(rGPU, cfg.Param[sModel]) |
| | | if handle == nil { |
| | |
| | | |
| | | return &reid{ |
| | | handle: handle, |
| | | list: sdkhelper.NewLockList(6), |
| | | fnLogger: fn, |
| | | |
| | | gpu: rGPU, |
| | | ipc: cfg.Param[sIPC], |
| | | } |
| | | } |
| | |
| | | |
| | | msg, err = c.Recv() |
| | | if err != nil { |
| | | s.fnLogger("REID~~~~~~Recv Image Error : ", err) |
| | | continue |
| | | } |
| | | |
| | | i := &protomsg.Image{} |
| | | err := proto.Unmarshal(msg, i) |
| | | if err != nil { |
| | |
| | | s.fnLogger("REID~~~~~~protomsg.Image data null") |
| | | continue |
| | | } |
| | | s.fnLogger("REID~~~~~~Recv Image:", len(i.Data)) |
| | | |
| | | ///////////////////////////////// |
| | | if jpg, err := godraw.ToJpeg(i.Data, int(i.Width), int(i.Height), nil); err == nil { |
| | | ioutil.WriteFile("./pic.jpg", jpg, 0644) |
| | | } |
| | | ///////////////////////////////// |
| | | feat := s.handle.Extract2(unsafe.Pointer(&i.Data[0]), int(i.Width), int(i.Height), 3) |
| | | if feat == nil { |
| | | // feat = make([]float32, 1) |
| | | } else { |
| | | for k := 0; k < 3; k++ { |
| | | s.fnLogger("REID~~~~~~extractor---human_feats------%f", feat[k+2000]) |
| | | } |
| | | s.fnLogger("REID~~~~~~Run Reid Use GPU: ", s.gpu) |
| | | |
| | | ///////////////////////////////// |
| | | if f, err := os.Create("./origin-feat.txt"); err == nil { |
| | | defer f.Close() |
| | | |
| | | w := bufio.NewWriter(f) |
| | | for k, v := range feat { |
| | | lineStr := fmt.Sprintf("%d->%f", k, v) |
| | | fmt.Fprintln(w, lineStr) |
| | | } |
| | | w.Flush() |
| | | } |
| | | ///////////////////////////////// |
| | | |
| | | } |
| | | buf := float32SliceAsByteSlice(feat) |
| | | ioutil.WriteFile("./feat.txt", buf, 0644) |
| | | c.Send(buf) |
| | | } |
| | | |
| | |
| | | |
| | | l := len(src) * 4 |
| | | ptr := unsafe.Pointer(&src[0]) |
| | | // It is important to keep in mind that the Go garbage collector |
| | | // will not interact with this data, and that if src if freed, |
| | | // the behavior of any Go code using the slice is nondeterministic. |
| | | // Reference: https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices |
| | | return (*[1 << 26]byte)((*[1 << 26]byte)(ptr))[:l:l] |
| | | } |