From: Francois Fleuret Date: Mon, 3 Sep 2012 08:08:08 +0000 (+0200) Subject: Added the fields force_empty_first_frame and force_empty_last_frame in MTPTracker. X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=mtp.git;a=commitdiff_plain;h=c7d5cdf1982dacc5451f79599041b2e95524d3f7 Added the fields force_empty_first_frame and force_empty_last_frame in MTPTracker. --- diff --git a/README.txt b/README.txt index 742dde3..2ce7e31 100644 --- a/README.txt +++ b/README.txt @@ -106,6 +106,8 @@ bool:allowed_motion_from_1_to_1 ... bool:allowed_motion_from_1_to_L ... bool:allowed_motion_from_L_to_1 ... bool:allowed_motion_from_L_to_L +bool:force_empty_first_frame bool:force_empty_last_frame + bool:is_an_entrance_1 ... bool:is_an_entrance_L bool:is_an_exit_1 ... bool:is_an_exit_L diff --git a/mtp_example.cc b/mtp_example.cc index fffeacb..92d4062 100644 --- a/mtp_example.cc +++ b/mtp_example.cc @@ -64,6 +64,9 @@ int main(int argc, char **argv) { tracker->exits[nb_locations - 1] = 1; } + tracker->force_empty_first_frame = 0; + tracker->force_empty_last_frame = 0; + // We construct the graph corresponding to this structure tracker->build_graph(); diff --git a/mtp_tracker.cc b/mtp_tracker.cc index c7c6602..b4e70ab 100644 --- a/mtp_tracker.cc +++ b/mtp_tracker.cc @@ -63,12 +63,15 @@ void MTPTracker::allocate(int t, int l) { } } + force_empty_first_frame = 0; + force_empty_last_frame = 0; + _edge_lengths = 0; _graph = 0; } void MTPTracker::write(ostream *os) { - (*os) << nb_locations << " " << nb_time_steps <> force_empty_first_frame >> force_empty_last_frame; + for(int l = 0; l < nb_locations; l++) { (*is) >> entrances[l]; } @@ -194,9 +203,6 @@ void MTPTracker::build_graph() { int nb_vertices = 2 + 2 * nb_time_steps * nb_locations; int nb_edges = - // The edges from the source to the first frame, and from the last - // frame to the sink - nb_locations * 2 + // The edges from the source to the entrances and from the exits // to the sink (in every time frames but the first for the // entrances, and last for the exits) @@ -206,6 +212,20 @@ void MTPTracker::build_graph() { // The edges inside the duplicated nodes nb_locations * nb_time_steps; + // Edges from the source to the first frame + if(force_empty_first_frame) { + nb_edges += nb_entrances; + } else { + nb_edges += nb_locations; + } + + // Edges from the last frame to the sink + if(force_empty_last_frame) { + nb_edges += nb_exits; + } else { + nb_edges += nb_locations; + } + int *node_from = new int[nb_edges]; int *node_to = new int[nb_edges]; @@ -229,19 +249,23 @@ void MTPTracker::build_graph() { // The edges from the source to the first time frame for(int l = 0; l < nb_locations; l++) { - node_from[e] = source; - node_to[e] = 1 + l + 0 * nb_locations; - _edge_lengths[e] = 0.0; - e++; + if(!force_empty_first_frame || entrances[l]) { + node_from[e] = source; + node_to[e] = 1 + l + 0 * nb_locations; + _edge_lengths[e] = 0.0; + e++; + } } // The edges from the last frame to the sink for(int l = 0; l < nb_locations; l++) { - node_from[e] = late_pair_node(nb_time_steps - 1, l); - node_to[e] = sink; - _edge_lengths[e] = 0.0; - e++; + if(!force_empty_last_frame || exits[l]) { + node_from[e] = late_pair_node(nb_time_steps - 1, l); + node_to[e] = sink; + _edge_lengths[e] = 0.0; + e++; + } } // The edges between frames, corresponding to allowed motions diff --git a/mtp_tracker.h b/mtp_tracker.h index 001bca1..1dcb94c 100644 --- a/mtp_tracker.h +++ b/mtp_tracker.h @@ -49,6 +49,7 @@ public: int nb_locations, nb_time_steps; int **allowed_motion; int *entrances, *exits; + int force_empty_first_frame, force_empty_last_frame; // The detection scores at each location and time scalar_t **detection_scores;