Cosmetics.
[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 #include <sys/time.h>
28
29 using namespace std;
30
31 #include "mtp_tracker.h"
32
33 scalar_t diff_in_second(struct timeval *start, struct timeval *end) {
34   return
35     scalar_t(end->tv_sec - start->tv_sec) +
36     scalar_t(end->tv_usec - start->tv_usec)/1000000;
37 }
38
39 int main(int argc, char **argv) {
40   timeval start_time, end_time;
41
42   if(argc < 2) {
43     cerr << argv[0] << " <tracker file>" << endl;
44     exit(EXIT_FAILURE);
45   }
46
47   ifstream *in_tracker = new ifstream(argv[1]);
48
49   if(in_tracker->good()) {
50
51     MTPTracker *tracker = new MTPTracker();
52
53     cout << "Reading " << argv[1] << "." << endl;
54     tracker->read(in_tracker);
55
56     cout << "Building the graph ... "; cout.flush();
57     gettimeofday(&start_time, 0);
58     tracker->build_graph();
59     gettimeofday(&end_time, 0);
60     cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl;
61
62     cout << "Tracking ... "; cout.flush();
63     gettimeofday(&start_time, 0);
64     tracker->track();
65     gettimeofday(&end_time, 0);
66     cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl;
67
68     ofstream out_traj("result.trj");
69     tracker->write_trajectories(&out_traj);
70     cout << "Wrote result.trj" << endl;
71
72     ofstream out_dot("graph.dot");
73     tracker->print_graph_dot(&out_dot);
74     cout << "Wrote graph.dot" << endl;
75
76     delete tracker;
77
78   } else {
79
80     cerr << "Can not open " << argv[1] << endl;
81     exit(EXIT_FAILURE);
82
83   }
84
85   delete in_tracker;
86
87   exit(EXIT_SUCCESS);
88 }