| | |
| | | // RatioInterTrack 跟踪判断重叠阈值 |
| | | const RatioInterTrack = 50 //跟踪判断重叠阈值 |
| | | |
| | | // SDKImage sdk image |
| | | type SDKImage struct { |
| | | Data []byte |
| | | Width int |
| | | Height int |
| | | Channel int |
| | | } |
| | | |
| | | // NewYolo init yolo sdk |
| | | func NewYolo(fc, fw, fn string, gi int) *YoloHandle { |
| | | // NewSDK init yolo sdk |
| | | func NewSDK(fc, fw, fn string, gi int) interface{} { |
| | | |
| | | c := C.CString(fc) |
| | | defer C.free(unsafe.Pointer(c)) |
| | |
| | | } |
| | | |
| | | // Free free |
| | | func (y *YoloHandle) Free() { |
| | | func Free(i interface{}) { |
| | | y := i.(*YoloHandle) |
| | | if y != nil { |
| | | if y.handle != nil { |
| | | C.release(y.handle) |
| | |
| | | } |
| | | |
| | | // YoloDetect yolo detect |
| | | func (y *YoloHandle) YoloDetect(data []byte, w, h, c int, thrsh float32, umns int) []CObjInfo { |
| | | func YoloDetect(y *YoloHandle, data []byte, w, h, c int, thrsh float32, umns int) []CObjInfo { |
| | | |
| | | var count C.int |
| | | var cobjinfo unsafe.Pointer |
| | |
| | | } |
| | | |
| | | // YoloObjName obj name by type |
| | | func (y *YoloHandle) YoloObjName(typ int) string { |
| | | func YoloObjName(i interface{}, typ int) string { |
| | | y := i.(*YoloHandle) |
| | | p := C.obj_name_by_type(y.handle, C.int(typ)) |
| | | |
| | | return C.GoString(p) |
| | |
| | | } |
| | | |
| | | // YoloDetectTrack2 yolo detect (只识别人) |
| | | func (y *YoloHandle) YoloDetectTrack2(LastYoloObjs []CObjTrackInfo, LastTrackID *uint64, data []byte, w, h, c int, thrsh float32, umns int) (allObjs []CObjTrackInfo, newObjs []CObjTrackInfo) { |
| | | func YoloDetectTrack2(y *YoloHandle, LastYoloObjs []CObjTrackInfo, LastTrackID *uint64, data []byte, w, h, c int, thrsh float32, umns int) (allObjs []CObjTrackInfo, newObjs []CObjTrackInfo) { |
| | | |
| | | var tmp CObjTrackInfo |
| | | //LastYoloObjs |
| | | detectObjs := y.YoloDetect(data, w, h, c, thrsh, umns) |
| | | detectObjs := YoloDetect(y, data, w, h, c, thrsh, umns) |
| | | |
| | | for _, vLast := range LastYoloObjs { |
| | | for i := 0; i < len(detectObjs); i++ { |
| | |
| | | return allObjs, newObjs |
| | | } |
| | | |
| | | // Run yolo detect (只识别人) |
| | | func Run(i interface{}, id string, data []byte, w, h, c int, thrsh float32, umns int) ([]byte, int) { |
| | | if data == nil || w <= 0 || h <= 0 { |
| | | return nil, 0 |
| | | } |
| | | y := i.(*YoloHandle) |
| | | |
| | | channel := c |
| | | if channel == 0 { |
| | | channel = 3 |
| | | } |
| | | |
| | | v, ok := y.tracker[id] |
| | | if !ok { |
| | | i := &trackInfo{} |
| | | y.tracker[id] = i |
| | | v = i |
| | | } |
| | | whole, _ := YoloDetectTrack2(y, v.lastTrackObjs, &v.lastTrackID, data, w, h, channel, thrsh, umns) |
| | | y.tracker[id].lastTrackObjs = whole |
| | | y.tracker[id].lastTrackID = v.lastTrackID |
| | | |
| | | var dWhole []byte |
| | | var err error |
| | | if len(whole) > 0 { |
| | | |
| | | infos := convert2ProtoYoloTrack(whole, 1.0, 1.0) |
| | | p := protomsg.ParamYoloObj{Infos: infos} |
| | | |
| | | dWhole, err = proto.Marshal(&p) |
| | | if err != nil { |
| | | fmt.Println("ydetect track marshal proto yolo obj error", err) |
| | | dWhole = nil |
| | | } |
| | | } |
| | | |
| | | return dWhole, len(whole) |
| | | } |
| | | |
| | | func convert2ProtoYoloTrack(obj []CObjTrackInfo, fx, fy float64) []*protomsg.ObjInfo { |
| | | ret := []*protomsg.ObjInfo{} |
| | | |
| | |
| | | return ret |
| | | } |
| | | |
| | | // YoloDetectTrack yolo detect (只识别人) |
| | | func (y *YoloHandle) YoloDetectTrack(id string, data []byte, w, h, c int, thrsh float32, umns int) ([]byte, []byte) { |
| | | // Run2 yolo detect (只识别人) |
| | | func Run2(i interface{}, id string, data []byte, w, h, c int, thrsh float32, umns int) ([]byte, int, []byte, int) { |
| | | if data == nil || w <= 0 || h <= 0 { |
| | | return nil, 0, nil, 0 |
| | | } |
| | | y := i.(*YoloHandle) |
| | | |
| | | channel := c |
| | | if channel == 0 { |
| | | channel = 3 |
| | | } |
| | | |
| | | v, ok := y.tracker[id] |
| | | if !ok { |
| | |
| | | y.tracker[id] = i |
| | | v = i |
| | | } |
| | | whole, recent := y.YoloDetectTrack2(v.lastTrackObjs, &v.lastTrackID, data, w, h, c, thrsh, umns) |
| | | whole, recent := YoloDetectTrack2(y, v.lastTrackObjs, &v.lastTrackID, data, w, h, channel, thrsh, umns) |
| | | y.tracker[id].lastTrackObjs = whole |
| | | y.tracker[id].lastTrackID = v.lastTrackID |
| | | |
| | |
| | | if len(recent) > 0 { |
| | | dRecent = nil |
| | | } |
| | | return dWhole, dRecent |
| | | return dWhole, len(whole), dRecent, len(recent) |
| | | } |