From 9cc6d3565364292ea9411a05d1e5d89aeb592585 Mon Sep 17 00:00:00 2001 From: diegohce Date: Wed, 28 Aug 2024 22:46:23 -0300 Subject: [PATCH] added TrackerGOTURN (see roadmap) added TrackerGOTURN (see roadmap) --- video.cpp | 10 ++++++++++ video.go | 24 ++++++++++++++++++++++++ video.h | 5 +++++ video_test.go | 2 +- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/video.cpp b/video.cpp index 6e9f17a0..862fcf76 100644 --- a/video.cpp +++ b/video.cpp @@ -76,6 +76,14 @@ void TrackerMIL_Close(TrackerMIL self) { delete self; } +TrackerGOTURN TrackerGOTURN_Create(void){ + return new cv::Ptr(cv::TrackerGOTURN::create()); +} + +void TrackerGOTURN_Close(TrackerGOTURN tr) { + delete tr; +} + KalmanFilter KalmanFilter_New(int dynamParams, int measureParams) { return new cv::KalmanFilter(dynamParams, measureParams, 0, CV_32F); } @@ -207,3 +215,5 @@ void KalmanFilter_SetGain(KalmanFilter kf, Mat gain) { void KalmanFilter_SetErrorCovPost(KalmanFilter kf, Mat errorCovPost) { kf->errorCovPost = *errorCovPost; } + + diff --git a/video.go b/video.go index c53a3d6e..d235e45f 100644 --- a/video.go +++ b/video.go @@ -249,6 +249,30 @@ func (trk TrackerMIL) Update(img Mat) (image.Rectangle, bool) { return trackerUpdate(C.Tracker(trk.p), img) } +type TrackerGOTURN struct { + p C.TrackerGOTURN +} + +func NewTrackerGOTURN() TrackerGOTURN { + return TrackerGOTURN{p: C.TrackerGOTURN_Create()} +} + +func (t TrackerGOTURN) Init(mat Mat, boundingBox image.Rectangle) bool { + return trackerInit(C.Tracker(t.p), mat, boundingBox) +} + +func (t TrackerGOTURN) Update(mat Mat) (image.Rectangle, bool) { + return trackerUpdate(C.Tracker(t.p), mat) + +} + +func (t TrackerGOTURN) Close() error { + C.TrackerGOTURN_Close(t.p) + t.p = nil + return nil + +} + // KalmanFilter implements a standard Kalman filter http://en.wikipedia.org/wiki/Kalman_filter. // However, you can modify transitionMatrix, controlMatrix, and measurementMatrix // to get an extended Kalman filter functionality. diff --git a/video.h b/video.h index 76cfddcc..866a6e3a 100644 --- a/video.h +++ b/video.h @@ -49,6 +49,9 @@ bool Tracker_Update(Tracker self, Mat image, Rect* boundingBox); TrackerMIL TrackerMIL_Create(); void TrackerMIL_Close(TrackerMIL self); +TrackerGOTURN TrackerGOTURN_Create(void); +void TrackerGOTURN_Close(TrackerGOTURN tr); + KalmanFilter KalmanFilter_New(int dynamParams, int measureParams); KalmanFilter KalmanFilter_NewWithParams(int dynamParams, int measureParams, int controlParams, int type); void KalmanFilter_Close(KalmanFilter kf); @@ -86,6 +89,8 @@ void KalmanFilter_SetErrorCovPre(KalmanFilter kf, Mat errorCovPre); void KalmanFilter_SetGain(KalmanFilter kf, Mat gain); void KalmanFilter_SetErrorCovPost(KalmanFilter kf, Mat errorCovPost); + + #ifdef __cplusplus } #endif diff --git a/video_test.go b/video_test.go index f20069f1..4b90cdcc 100644 --- a/video_test.go +++ b/video_test.go @@ -291,7 +291,7 @@ func TestSingleTrackers(t *testing.T) { tracker Tracker }{ {"MIL", NewTrackerMIL()}, - // {"GOTURN", NewTrackerGOTURN()}, + {"GOTURN", NewTrackerGOTURN()}, } for _, test := range tab {