3 * mtp is the ``Multi Tracked Paths'', an implementation of the
4 * k-shortest paths algorithm for multi-target tracking.
6 * Copyright (c) 2012 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of mtp.
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.
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.
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/>.
33 #include "mtp_tracker.h"
35 #define FILENAME_SIZE 1024
37 char trajectory_filename[FILENAME_SIZE];
38 char graph_filename[FILENAME_SIZE];
41 void usage(ostream *os) {
42 (*os) << "mtp [-h|--help] [-v|--verbose] [-t|--trajectory-filename <trajectory filename>] [-g|--graph-filename <graph filename>] [<tracking parameter file>]" << endl;
44 (*os) << "The mtp command processes a file containing the description of a topology" << endl;
45 (*os) << "and detection scores, and prints the optimal set of trajectories." << endl;
46 (*os) << "If no filename is provided, it will read the parameters from the stdin." << endl;
47 (*os) << "If no trajectory filename is provided, it will write the result to" << endl;
48 (*os) << "stdout." << endl;
50 (*os) << "Written by Francois Fleuret. (C) Idiap Research Institute, 2012." << endl;
53 scalar_t diff_in_second(struct timeval *start, struct timeval *end) {
55 scalar_t(end->tv_sec - start->tv_sec) +
56 scalar_t(end->tv_usec - start->tv_usec)/1000000;
59 void do_tracking(istream *in_tracker) {
60 timeval start_time, end_time;
61 MTPTracker *tracker = new MTPTracker();
63 if(verbose) { cout << "Reading the tracking parameters." << endl; }
64 tracker->read(in_tracker);
67 cout << "Building the graph ... "; cout.flush();
68 gettimeofday(&start_time, 0);
70 tracker->build_graph();
72 gettimeofday(&end_time, 0);
73 cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl;
77 cout << "Tracking ... "; cout.flush();
78 gettimeofday(&start_time, 0);
82 gettimeofday(&end_time, 0);
83 cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl;
86 if(strcmp(trajectory_filename, "")) {
87 ofstream out_traj(trajectory_filename);
88 tracker->write_trajectories(&out_traj);
89 if(verbose) { cout << "Wrote " << trajectory_filename << "." << endl; }
91 tracker->write_trajectories(&cout);
94 if(strcmp(graph_filename, "") != 0) {
95 ofstream out_dot(graph_filename);
96 tracker->print_graph_dot(&out_dot);
97 if(verbose) { cout << "Wrote " << graph_filename << "." << endl; }
103 static struct option long_options[] = {
104 { "trajectory-file", 1, 0, 't' },
105 { "graph-file", 1, 0, 'g' },
106 { "help", no_argument, 0, 'h' },
107 { "verbose", no_argument, 0, 'v' },
111 int main(int argc, char **argv) {
113 int error = 0, show_help = 0;
115 strncpy(trajectory_filename, "", FILENAME_SIZE);
116 strncpy(graph_filename, "", FILENAME_SIZE);
119 while ((c = getopt_long(argc, argv, "t:g:hv",
120 long_options, NULL)) != -1) {
125 strncpy(trajectory_filename, optarg, FILENAME_SIZE);
129 strncpy(graph_filename, optarg, FILENAME_SIZE);
157 ifstream *file_in_tracker = new ifstream(argv[optind]);
158 if(file_in_tracker->good()) {
159 do_tracking(file_in_tracker);
161 cerr << "Can not open " << argv[optind] << endl;
164 delete file_in_tracker;