From 1f4d33dfe85996040235f46aeccb4f0f8bb23e58 Mon Sep 17 00:00:00 2001 From: Brenno Date: Mon, 15 Mar 2021 21:45:31 -0300 Subject: [PATCH] Using normalized initial bounding box on CVTracker --- src/CVTracker.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/CVTracker.cpp b/src/CVTracker.cpp index f86448594..74cd46b1d 100644 --- a/src/CVTracker.cpp +++ b/src/CVTracker.cpp @@ -108,6 +108,12 @@ void CVTracker::trackClip(openshot::Clip& video, size_t _start, size_t _end, boo // Grab OpenCV Mat image cv::Mat cvimage = f->GetImageCV(); + if(frame == start){ + // Take the normalized inital bounding box and multiply to the current video shape + bbox = cv::Rect2d(bbox.x*cvimage.cols,bbox.y*cvimage.rows,bbox.width*cvimage.cols, + bbox.height*cvimage.rows); + } + // Pass the first frame to initialize the tracker if(!trackerInit){ @@ -284,10 +290,10 @@ void CVTracker::SetJsonValue(const Json::Value root) { } if (!root["region"].isNull()){ - double x = root["region"]["x"].asDouble(); - double y = root["region"]["y"].asDouble(); - double w = root["region"]["width"].asDouble(); - double h = root["region"]["height"].asDouble(); + double x = root["region"]["normalized_x"].asDouble(); + double y = root["region"]["normalized_y"].asDouble(); + double w = root["region"]["normalized_width"].asDouble(); + double h = root["region"]["normalized_height"].asDouble(); cv::Rect2d prev_bbox(x,y,w,h); bbox = prev_bbox; }