2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation. //
7 // This program is distributed in the hope that it will be useful, but //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
10 // General Public License for more details. //
12 // You should have received a copy of the GNU General Public License //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
15 // Written by and Copyright (C) Francois Fleuret //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
17 ///////////////////////////////////////////////////////////////////////////
28 //////////////////////////////////////////////////////////////////////
30 scalar_t detection_score(scalar_t a, scalar_t b, scalar_t score_noise, scalar_t flip_noise) {
31 if(drand48() > flip_noise) {
32 return a + score_noise * (2.0 * drand48() - 1.0);
34 return b + score_noise * (2.0 * drand48() - 1.0);
38 int main(int argc, char **argv) {
40 int nb_time_steps = 8;
41 int motion_amplitude = 1;
43 Tracker *tracker = new Tracker();
45 tracker->allocate(nb_time_steps, nb_locations);
47 // We define the spatial structures by stating what are the possible
48 // motions of targets, and what are the entrances and the
51 // Here our example is a 1D space with motions from any location to
52 // any location less than motion_amplitude away, entrance at
53 // location 0 and exit at location nb_locations-1.
55 for(int l = 0; l < nb_locations; l++) {
56 for(int k = 0; k < nb_locations; k++) {
57 tracker->allowed_motion[l][k] = abs(l - k) <= motion_amplitude;
59 tracker->entrances[0] = 1;
60 tracker->exits[nb_locations - 1] = 1;
63 // We construct the graph corresponding to this structure
65 tracker->build_graph();
67 // Then, we specify for every location and time step what is the
68 // detection score there.
70 scalar_t flip_noise = 0.05;
71 scalar_t score_noise = 0.0;
73 // We first put a background noise, with negative scores at every
76 for(int t = 0; t < nb_time_steps; t++) {
77 for(int l = 0; l < nb_locations; l++) {
78 tracker->detection_scores[t][l] = detection_score(-1.0, 1.0, score_noise, flip_noise);
82 // Then we two targets with the typical local minimum:
84 // * Target A moves from location 0 to the middle, stays there for a
85 // while, and comes back, and is strongly detected on the first
88 // * Target B moves from location nb_locations-1 to the middle, stay
89 // there for a while, and comes back, and is strongly detected on
92 int la, lb; // Target locations
93 scalar_t sa, sb; // Target detection scores
94 for(int t = 0; t < nb_time_steps; t++) {
95 if(t < nb_time_steps/2) {
97 lb = nb_locations - 1 - t;
98 sa = detection_score(10.0, -1.0, score_noise, flip_noise);
99 sb = detection_score( 1.0, -1.0, score_noise, flip_noise);
101 la = nb_time_steps - 1 - t;
102 lb = t - nb_time_steps + nb_locations;
103 sa = detection_score( 1.0, -1.0, score_noise, flip_noise);
104 sb = detection_score(10.0, -1.0, score_noise, flip_noise);
107 if(la > nb_locations/2 - 1) la = nb_locations/2 - 1;
108 if(lb < nb_locations/2 + 1) lb = nb_locations/2 + 1;
110 tracker->detection_scores[t][la] = sa;
111 tracker->detection_scores[t][lb] = sb;
114 { // Write down the tracker setting
115 ofstream out_tracker("tracker.dat");
116 tracker->write(&out_tracker);
119 // Does the tracking per se
123 // Prints the detected trajectories
125 for(int t = 0; t < tracker->nb_trajectories(); t++) {
126 cout << "Trajectory "
128 << " starting at " << tracker->trajectory_entrance_time(t)
129 << ", duration " << tracker->trajectory_duration(t)
130 << ", score " << tracker->trajectory_score(t)
131 << ", through nodes ";
132 for(int u = 0; u < tracker->trajectory_duration(t); u++) {
133 cout << " " << tracker->trajectory_location(t, u);