Added the timing of the graph building and tracking in seconds.
[mtp.git] / mtp.cc
1
2 /*
3  *  mtp is the ``Multi Tracked Paths'', an implementation of the
4  *  k-shortest paths algorithm for multi-target tracking.
5  *
6  *  Copyright (c) 2012 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of mtp.
10  *
11  *  mtp is free software: you can redistribute it and/or modify it
12  *  under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  mtp is distributed in the hope that it will be useful, but WITHOUT
16  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
18  *  License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with selector.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include <iostream>
26 #include <fstream>
27
28 using namespace std;
29
30 #include "mtp_tracker.h"
31
32 int main(int argc, char **argv) {
33   time_t start_time, end_time;
34
35   if(argc < 2) {
36     cerr << argv[0] << " <tracker file>" << endl;
37     exit(EXIT_FAILURE);
38   }
39
40   ifstream *in_tracker = new ifstream(argv[1]);
41
42   if(in_tracker->good()) {
43
44     MTPTracker *tracker = new MTPTracker();
45
46     cout << "Reading " << argv[1] << "." << endl;
47     tracker->read(in_tracker);
48
49     cout << "Building the graph ... "; cout.flush();
50     start_time = time(0);
51     tracker->build_graph();
52     end_time = time(0);
53     cout << "done (" << end_time - start_time << "s)." << endl;
54
55     cout << "Tracking ... "; cout.flush();
56     start_time = time(0);
57     tracker->track();
58     end_time = time(0);
59     cout << "done (" << end_time - start_time << "s)." << endl;
60
61     ofstream out_traj("result.trj");
62     tracker->write_trajectories(&out_traj);
63     cout << "Wrote result.trj" << endl;
64
65     ofstream out_dot("graph.dot");
66     tracker->print_graph_dot(&out_dot);
67     cout << "Wrote graph.dot" << endl;
68
69     delete tracker;
70
71   } else {
72
73     cerr << "Can not open " << argv[1] << endl;
74     exit(EXIT_FAILURE);
75
76   }
77
78   delete in_tracker;
79
80   exit(EXIT_SUCCESS);
81 }