| | |
| | | package sdk |
| | | |
| | | import ( |
| | | "analysis/goconv" |
| | | "analysis/logo" |
| | | "analysis/work" |
| | | "context" |
| | |
| | | |
| | | type imageWithID struct { |
| | | img *gohumantrack.ImageHumanTracker |
| | | fx float32 |
| | | fy float32 |
| | | id string |
| | | } |
| | | |
| | |
| | | |
| | | imgW, imgH := int(i.Width), int(i.Height) |
| | | |
| | | var imgData []byte |
| | | rw, rh := 1280, 720 |
| | | fx, fy := 1.0, 1.0 |
| | | if imgW != rw || imgH != rh { |
| | | imgData = goconv.ResizeBGR(i.Data, imgW, imgH, rw, rh) |
| | | fx = (float32)(rw)/(float32)imgW |
| | | fy = (float32)(rh)/(float32)imgH |
| | | } |
| | | img := gohumantrack.ImageHumanTracker{ |
| | | Data: i.Data, |
| | | Width: imgW, |
| | |
| | | |
| | | if i, ok := t.mapCameraImageIndex[rMsg.Msg.Cid]; ok { |
| | | if i < t.batchSize { |
| | | t.images[i] = &imageWithID{&img, rMsg.Msg.Cid} |
| | | t.images[i] = &imageWithID{&img, fx, fy, rMsg.Msg.Cid} |
| | | t.msgs[i] = &rMsg |
| | | } |
| | | } else { |
| | | if t.index < t.batchSize { |
| | | t.images[t.index] = &imageWithID{&img, rMsg.Msg.Cid} |
| | | t.images[t.index] = &imageWithID{&img, fx, fy, rMsg.Msg.Cid} |
| | | t.msgs[t.index] = &rMsg |
| | | t.mapCameraImageIndex[rMsg.Msg.Cid] = t.index |
| | | } |
| | |
| | | if t.images[i] == nil { |
| | | continue |
| | | } |
| | | hr := convert2ProtoHumanTrackResult(res[i]) |
| | | hr := convert2ProtoHumanTrackResultWithScale(res[i], t.images[i].fx, t.images[i].fy) |
| | | result := protomsg.HumanTrackResult{Result: hr} |
| | | data, err := proto.Marshal(&result) |
| | | if err != nil { |
| | |
| | | } |
| | | return res |
| | | } |
| | | |
| | | func convert2ProtoHumanTrackResultWithScale(obj gohumantrack.FgResult, fx, fy float32) []*protomsg.HumanTrack { |
| | | res := []*protomsg.HumanTrack{} |
| | | for i := 0; i < int(obj.FgNum); i++ { |
| | | r := obj.Fginfo[i] |
| | | rect := protomsg.Rect{ |
| | | Left: (int32)((float32)(r.Left)/fx), |
| | | Right: (int32)((float32)(r.Right)/fy), |
| | | Top: (int32)((float32)(r.Top)/fx), |
| | | Bottom: (int32)((float32)(r.Bottom)/fy), |
| | | } |
| | | pr := &protomsg.HumanTrack{ |
| | | RcHuman: &rect, |
| | | Confidence: r.Confidence, |
| | | X: (int32)((float32)(r.X)/fx, |
| | | Y: (int32)((float32)(r.Y)/fy, |
| | | Id: r.ID, |
| | | Feature: r.Feature[:], |
| | | } |
| | | res = append(res, pr) |
| | | } |
| | | return res |
| | | } |