Added README.md
[mtp.git] / mtp_tracker.h
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 #ifndef MTP_TRACKER_H
26 #define MTP_TRACKER_H
27
28 #include <iostream>
29
30 using namespace std;
31
32 #include "misc.h"
33 #include "mtp_graph.h"
34
35 class MTPTracker {
36   MTPGraph *_graph;
37
38   // The edges will be ordered as follows: First the nb_locations *
39   // nb_time_steps edges inside the node pairs, which will have
40   // lengths equal to the opposite of the detection scores, then the
41   // edges between these node pairs, and finally the edges from source
42   // and to sink.
43   scalar_t *_edge_lengths;
44
45   int early_pair_node(int t, int l);
46   int late_pair_node(int t, int l);
47
48 public:
49
50   // The spatial structure
51   int nb_locations, nb_time_steps;
52   int **allowed_motions;
53   int **entrances, **exits;
54
55   // The detection scores at each location and time
56   scalar_t **detection_scores;
57
58   MTPTracker();
59   ~MTPTracker();
60
61   void allocate(int nb_time_steps, int nb_locations);
62   void free();
63
64   void write(ostream *os);
65   void read(istream *is);
66   void write_trajectories(ostream *os);
67
68   // Build or print the graph needed for the tracking per se
69
70   void build_graph();
71   void print_graph_dot(ostream *os);
72
73   // Compute the optimal set of trajectories
74
75   void track();
76
77   // Read-out of the optimal trajectories
78
79   int nb_trajectories();
80   scalar_t trajectory_score(int k);
81   int trajectory_entrance_time(int k);
82   int trajectory_duration(int k);
83   int trajectory_location(int k, int time_from_entry);
84 };
85
86 #endif