C++ Dlib: Image Tracking

C++ Dlib: Image Tracking

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],

std::sort(files.begin(), files.end());

    if (files.size()
== 0)


        cout <<
"No images found in " << argv[1] << endl;

        return 1;



array2d<unsigned char> img;




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]);





       cout <<"hit enter to process next frame" << endl;




catch (std::exception& e)


    cout <<
e.what() << endl;