The correlation tracker from the dlib C++ library is used in the programme that follows to demonstrate its use. This enables you to follow an object's position as it changes during a video clip. You utilise it by providing the correlation tracker with the bounding box of the object in the current video frame that you wish to track. The object's position will then be revealed in later frames.
#include <iostream>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/dir_nav.h>
using namespace dlib;
using namespace std;
int main(int argc, char** argv) try
{
if (argc != 2)
{
cout<< "Call this program like this: " << endl;
cout << "./video_tracking_ex ../video_frames" << endl;
return 1;
}
std::vector<file> files = get_files_in_directory_tree(argv[1],
match_ending(".jpg"));
std::sort(files.begin(), files.end());
if (files.size()
== 0)
{
cout <<
"No images found in " << argv[1] << endl;
return 1;
}
array2d<unsigned char> img;
load_image(img,
files[0]);
correlation_tracker
tracker;
tracker.start_track(img, centered_rect(point(93, 110), 38, 86));
image_window win;
for (unsigned long i = 1; i < files.size(); ++i) {
load_image(img, files[i]);
tracker.update(img);
win.set_image(img);
win.clear_overlay();
win.add_overlay(tracker.get_position());
cout <<"hit enter to process next frame" << endl;
cin.get();
}
}
catch (std::exception& e)
{
cout <<
e.what() << endl;
}
Name | Views | Likes |
---|---|---|
C++ Dlib: Timer | 216 | 0 |
C++ Matplot: Undirected Graph | 197 | 0 |
C++ Matplot: Directed Graph | 175 | 0 |
C++ Matplot: Quiver Plot | 239 | 0 |
C++ Matplot: Polar Histogram | 244 | 0 |
C++ Matplot: Pie Chart | 189 | 0 |
C++ Matplot: Heatmap | 618 | 0 |
C++ Matplot: Scatterplot | 633 | 0 |
C++ Matplot: Histogram | 183 | 0 |
C++ Matplot: Boxplot | 296 | 0 |
C++ Matplot: Introduction | 230 | 0 |
C++ Dlib: SQLite | 178 | 0 |
C++ Dlib: Parallel For Loop | 172 | 0 |
C++ Dlib: Max Cost Function | 157 | 0 |
C++ Dlib: Logger | 153 | 0 |
C++ Dlib: Image | 161 | 0 |
C++ Dlib: Non Linear Optimization Routine | 187 | 0 |
C++ Dlib: Face Pose Detection | 131 | 0 |
C++ Dlib: Matrix Multiplication | 140 | 0 |
C++ Dlib: XML Parser | 136 | 0 |
C++ Dlib: Object Detection | 134 | 0 |
C++ Dlib: Face Detection | 259 | 0 |
C++ Dlib: Image Tracking | 253 | 0 |
C++: Dlib Installation | 143 | 0 |
C++ Dlib: Introduction | 165 | 0 |
Comments