Video Analysis底层库拆分,sdk的go封装
zhangmeng
2019-07-15 76f25eb0e46494b7f564e704f422002331a969a5
add fn yolodetecttrack2
1个文件已修改
43 ■■■■■ 已修改文件
gosdk.go 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gosdk.go
@@ -21,6 +21,7 @@
    LastYoloObjs []CObjTrackInfo //yolo跟踪的上一帧信息
    LastTrackID uint64       //yolo 被使用的ID
}
const RatioInterTrack = 50       //跟踪判断重叠阈值
// SDKImage sdk image
@@ -362,3 +363,45 @@
    return allObjs, newObjs
}
// YoloDetectTrack2 yolo detect   (只识别人)
func YoloDetectTrack2(handle *YoloHandle, LastYoloObjs []CObjTrackInfo, LastTrackID *uint64, img SDKImage, thrsh float32, umns int) (allObjs []CObjTrackInfo, newObjs []CObjTrackInfo) {
    var tmp CObjTrackInfo
    //LastYoloObjs
    detectObjs := YoloDetect(handle, img, thrsh, umns)
    for _, vLast := range LastYoloObjs {
        for i := 0; i < len(detectObjs); i++ {
            //fmt.Println("vNew.Typ:", vNew.Typ)
            if vLast.ObjInfo.Typ == detectObjs[i].Typ { //同一类别,比如都是人体
                ratio := countInterAreaOfTwoRect(vLast.ObjInfo.RcObj, detectObjs[i].RcObj)
                if ratio >= RatioInterTrack {
                    //update LastYoloObjs
                    vLast.ObjInfo.RcObj = detectObjs[i].RcObj
                    vLast.ObjInfo.Prob = detectObjs[i].Prob
                    allObjs = append(allObjs, vLast)
                    detectObjs = append(detectObjs[:i], detectObjs[i+1:]...) //从检测目标里删除已经查到的跟踪目标
                    i--
                    break //上一帧跟踪的目标已经找到,无需往下处理其他检测目标
                }
            }
        }
    }
    //处理新出现的目标
    id := *LastTrackID
    if len(detectObjs) > 0 {
        for _, vAdd := range detectObjs {
            tmp.ObjInfo = vAdd
            tmp.ID = id
            id++
            allObjs = append(allObjs, tmp)
            newObjs = append(newObjs, tmp)
        }
    }
    *LastTrackID = id
    return allObjs, newObjs
}