Skip to content

Commit

Permalink
tracking in tex
Browse files Browse the repository at this point in the history
and changed name of class
  • Loading branch information
albertopasqualetto committed Jul 21, 2024
1 parent 186836b commit a2155b2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
Binary file modified Report/main.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions Report/section/tracking.tex
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
\subsection{Tracking}
The tracking has been performed exploiting the \texttt{TrackerCSRT} class of the OpenCV library.

In our application a new class \texttt{BilliardTracker} has been implemented, which is responsible for the tracking of all the balls on the billiard table while adding the lower level implementation of OpenCV \texttt{TrackerCSRT}. The class works by creating a new \texttt{TrackerCSRT} object for each ball to be tracked.

During the tracking process, at every frame, the tracker updates the global \texttt{Ball} vector with the new position of the ball through a pointer which will be used to draw the ball and its trace on the minimap.
The position of the ball is only updated if the updated bounding box is moved by at least a certain threshold, which is set to the 70\% of the IoU between the previous and the new bounding box. This is done to avoid some false positives that may occur during the tracking which lead to small wiggles in the ball position, even if they are steady.
The IoU threshold value is a trade off between the wiggle reduction and the time frequency sampling of the ball position, used to draw the trace of the ball on the minimap.

If the ball is no more visible since it has been scored, then the relative tracking is stopped.

Based on our experiments the tracking is performed on a 10 pixels padded version of the ball's bounding box since the tracker gains much more performances in its ability to track the ball, even without occlusions.

This tracking implementation reveals to be very robust and accurate on all the frames of all videos of the dataset, but it is also very slow; this is the bottlneck of the application, since the tracking is performed on every frame of the video, and the tracking of each ball is performed independently from the others.
4 changes: 2 additions & 2 deletions include/tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @brief Class that tracks all the balls in the input image, it relies on OpenCV TrackerCSRT class.
*/
class BallTracker {
class BilliardTracker {
std::vector<cv::Ptr<cv::Tracker>> ballTrackers_; // vector of OpenCV Tracker objects, one for each ball. The index in the vector is the same as the index in ballsVec_.
cv::Ptr<std::vector<Ball>> ballsVec_; // pointer to the vector of balls to track.
bool isInitialized_; // flag that indicates if the trackers have already been initialized.
Expand All @@ -25,7 +25,7 @@ class BallTracker {
* @brief Constructor.
* @param balls pointer to the vector of balls to track.
*/
explicit BallTracker(cv::Ptr<std::vector<Ball>> balls);
explicit BilliardTracker(cv::Ptr<std::vector<Ball>> balls);

/**
* @brief Track the ball with the given index in the input frame.
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) {
vidOutput.write(res);

//TRACKER
BallTracker tracker = BallTracker(table.ballsPtr());
BilliardTracker tracker = BilliardTracker(table.ballsPtr());
tracker.trackAll(frame);

//VIDEO WITH MINIMAP
Expand Down
12 changes: 6 additions & 6 deletions src/tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace cv;
* @brief Constructor.
* @param balls pointer to the vector of balls to track.
*/
BallTracker::BallTracker(Ptr<std::vector<Ball>> balls) { // NOLINT(*-unnecessary-value-param)
BilliardTracker::BilliardTracker(Ptr<std::vector<Ball>> balls) { // NOLINT(*-unnecessary-value-param)
//std::cout<<"constructor balltracker"<<std::endl;
isInitialized_ = false;

Expand All @@ -27,7 +27,7 @@ BallTracker::BallTracker(Ptr<std::vector<Ball>> balls) { // NOLINT(*-unnecessary
* @brief Create the trackers for all the balls in the vector.
* Used the first time tracker is called.
*/
void BallTracker::createTrackers() {
void BilliardTracker::createTrackers() {
for (unsigned short i = 0; i < ballsVec_->size(); i++) {
Ptr<Tracker> tracker = TrackerCSRT::create(); //parameters go here if necessary
ballTrackers_.push_back(tracker);
Expand All @@ -40,14 +40,14 @@ void BallTracker::createTrackers() {

/**
* @brief Track the ball with the given index in the input frame.
* It performs OpenCV Tracker initialization the first time it is called.
* It performs OpenCV Tracker initialization the first time it is called.
* The returned bounding box is not updated if the IoU with the previous one is too high.
* @param ballIndex index of the ball to track.
* @param frame input frame.
* @param callInit flag that indicates if the tracker has to be initialized.
* @return the bounding box of the tracked ball.
*/
Rect BallTracker::trackOne(unsigned short ballIndex, const Mat &frame, bool callInit /*= false*/) {
Rect BilliardTracker::trackOne(unsigned short ballIndex, const Mat &frame, bool callInit /*= false*/) {
Rect bbox = ballsVec_->at(ballIndex).getBbox();
ballsVec_->at(ballIndex).setBbox_prec(bbox);

Expand All @@ -56,7 +56,7 @@ Rect BallTracker::trackOne(unsigned short ballIndex, const Mat &frame, bool call
enlargeRect(bbox, 10); // enlarge bbox to enhance tracking performance
ballTrackers_[ballIndex]->init(frame, bbox);
} else {
if(ballsVec_->at(ballIndex).getVisibility())
if(ballsVec_->at(ballIndex).getVisibility()) // track only visible balls
{
isBboxUpdated = ballTrackers_[ballIndex]->update(frame, bbox);
const float IOU_THRESHOLD = 0.7;
Expand All @@ -80,7 +80,7 @@ Rect BallTracker::trackOne(unsigned short ballIndex, const Mat &frame, bool call
* @param frame input frame.
* @return a pointer to the vector of the tracked balls. It is the same as the one provided to the constructor.
*/
Ptr<std::vector<Ball>> BallTracker::trackAll(const Mat &frame) {
Ptr<std::vector<Ball>> BilliardTracker::trackAll(const Mat &frame) {
//std::cout<<"trackAll, initialized: "<<isInitialized_<<std::endl;
if (!isInitialized_) {
createTrackers();
Expand Down

0 comments on commit a2155b2

Please sign in to comment.