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;
45 scalar_t diff_in_second(struct timeval *start, struct timeval *end) {
47 scalar_t(end->tv_sec - start->tv_sec) +
48 scalar_t(end->tv_usec - start->tv_usec)/1000000;
51 void do_tracking(istream *in_tracker) {
52 timeval start_time, end_time;
53 MTPTracker *tracker = new MTPTracker();
55 if(verbose) { cout << "Reading the tracking parameters." << endl; }
56 tracker->read(in_tracker);
58 if(verbose) { cout << "Building the graph ... "; cout.flush(); }
59 gettimeofday(&start_time, 0);
60 tracker->build_graph();
61 gettimeofday(&end_time, 0);
62 if(verbose) { cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl; }
64 if(verbose) { cout << "Tracking ... "; cout.flush(); }
65 gettimeofday(&start_time, 0);
67 gettimeofday(&end_time, 0);
68 if(verbose) { cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl; }
70 if(strcmp(trajectory_filename, "")) {
71 ofstream out_traj(trajectory_filename);
72 tracker->write_trajectories(&out_traj);
73 if(verbose) { cout << "Wrote " << trajectory_filename << "." << endl; }
75 tracker->write_trajectories(&cout);
78 if(strcmp(graph_filename, "") != 0) {
79 ofstream out_dot(graph_filename);
80 tracker->print_graph_dot(&out_dot);
81 if(verbose) { cout << "Wrote " << graph_filename << "." << endl; }
87 static struct option long_options[] = {
88 { "trajectory-file", 1, 0, 't' },
89 { "graph-file", 1, 0, 'g' },
90 { "help", no_argument, 0, 'h' },
91 { "verbose", no_argument, 0, 'v' },
95 int main(int argc, char **argv) {
97 int error = 0, show_help = 0;
99 // strncpy(trajectory_filename, "result.trj", FILENAME_SIZE);
100 strncpy(trajectory_filename, "", FILENAME_SIZE);
101 strncpy(graph_filename, "", FILENAME_SIZE);
104 while ((c = getopt_long(argc, argv, "t:g:hv",
105 long_options, NULL)) != -1) {
110 strncpy(trajectory_filename, optarg, FILENAME_SIZE);
114 strncpy(graph_filename, optarg, FILENAME_SIZE);
142 ifstream *file_in_tracker = new ifstream(argv[optind]);
143 if(file_in_tracker->good()) {
144 do_tracking(file_in_tracker);
146 cerr << "Can not open " << argv[optind] << endl;
149 delete file_in_tracker;