Browse Source

n-stage now has constraints for every stage

Helge Wrede 8 years ago
parent
commit
c2a2f5b711
4 changed files with 27 additions and 19 deletions
  1. 9 5
      algo/NStage.cpp
  2. 2 2
      algo/NStage.h
  3. 16 9
      main/main.cpp
  4. 0 3
      util/Filter2D.h

+ 9 - 5
algo/NStage.cpp

@@ -12,7 +12,7 @@ namespace algo
                    std::vector<double> penalty_value,
                    std::vector<double> penalty_value,
                    std::vector<size_t> max_tracklet_count,
                    std::vector<size_t> max_tracklet_count,
                    double edge_weight_threshold,
                    double edge_weight_threshold,
-                   std::unordered_map<std::string, double> constraints)
+                   std::vector<std::unordered_map<std::string, double>> constraints)
     {
     {
         max_frame_skips_ = max_frame_skip;
         max_frame_skips_ = max_frame_skip;
         penalty_values_ = penalty_value;
         penalty_values_ = penalty_value;
@@ -72,7 +72,7 @@ namespace algo
                         Vertex v = layers[i + k][l];
                         Vertex v = layers[i + k][l];
 
 
                         // Only create the edge if the constraints are assured
                         // Only create the edge if the constraints are assured
-                        if (values[u]->IsWithinConstraints(values[v], constraints_))
+                        if (values[u]->IsWithinConstraints(values[v], constraints_[0]))
                         {
                         {
                             double weight = values[u]->CompareTo(values[v]);
                             double weight = values[u]->CompareTo(values[v]);
 
 
@@ -211,9 +211,13 @@ namespace algo
                     if (u_last_frame < v_first_frame &&
                     if (u_last_frame < v_first_frame &&
                             (v_first_frame - u_last_frame < max_frame_skips_[iteration]))
                             (v_first_frame - u_last_frame < max_frame_skips_[iteration]))
                     {
                     {
-                        boost::add_edge(u, v,
-                                        tlt_values[u]->CompareTo(tlt_values[v]),
-                                        tlt_graph);
+                        // Only create the edge if the constraints are assured
+                        if (u_ptr->IsWithinConstraints(v_ptr, constraints_[iteration]))
+                        {
+                            boost::add_edge(u, v,
+                                            tlt_values[u]->CompareTo(tlt_values[v]),
+                                            tlt_graph);
+                        }
                     }
                     }
                 }
                 }
             }
             }

+ 2 - 2
algo/NStage.h

@@ -46,7 +46,7 @@ namespace algo
         /**
         /**
          * The constraints to ensure when creating edges
          * The constraints to ensure when creating edges
          */
          */
-        std::unordered_map<std::string, double> constraints_;
+        std::vector<std::unordered_map<std::string, double>> constraints_;
 
 
         /**
         /**
          * Creates a graph with vertices for every detected object
          * Creates a graph with vertices for every detected object
@@ -94,7 +94,7 @@ namespace algo
                std::vector<double> penalty_value,
                std::vector<double> penalty_value,
                std::vector<size_t> max_tracklet_count,
                std::vector<size_t> max_tracklet_count,
                double edge_weight_threshold,
                double edge_weight_threshold,
-               std::unordered_map<std::string, double> constraints);
+               std::vector<std::unordered_map<std::string, double>> constraints);
 
 
         /**
         /**
          * Runs the algorithm on the specified sequence and stores the found tracks into the
          * Runs the algorithm on the specified sequence and stores the found tracks into the

+ 16 - 9
main/main.cpp

@@ -21,7 +21,7 @@ struct
     std::string max_tracklet_count;
     std::string max_tracklet_count;
     std::string penalty_value;
     std::string penalty_value;
     double edge_weight_threshold;
     double edge_weight_threshold;
-    std::unordered_map<std::string, double> constraints;
+    std::vector<std::unordered_map<std::string, double>> constraints;
 } n_stage_params;
 } n_stage_params;
 
 
 void RunNStage(core::DetectionSequence& sequence, std::vector<core::TrackletPtr>& tracks)
 void RunNStage(core::DetectionSequence& sequence, std::vector<core::TrackletPtr>& tracks)
@@ -244,8 +244,8 @@ void Run(int argc, char const * const * argv)
              boost::program_options::value<std::string>(&n_stage_constraints)
              boost::program_options::value<std::string>(&n_stage_constraints)
                      ->default_value(""),
                      ->default_value(""),
              "(n-stage) the constraints to ensure when creating the object graph,"
              "(n-stage) the constraints to ensure when creating the object graph,"
-                     " values and keys are separated by commas,"
-                     " for example: key0,value0,key1,value1")
+                     " values and keys are separated by commas, stages are separated by semicolons,"
+                     " for example: key00,value00,key01,value01;key11,value11,key12,value21")
             ("berclaz.h-res",
             ("berclaz.h-res",
              boost::program_options::value<int>(&berclaz_params.h_res)
              boost::program_options::value<int>(&berclaz_params.h_res)
                      ->default_value(10),
                      ->default_value(10),
@@ -395,15 +395,22 @@ void Run(int argc, char const * const * argv)
     begin_time = time(0);
     begin_time = time(0);
     if (algorithm == "n-stage")
     if (algorithm == "n-stage")
     {
     {
-        //TODO constraints for every stage not just the first
-
         // Parse the constraints
         // Parse the constraints
-        std::vector<std::string> pairs = util::FileIO::Split(n_stage_constraints, ',');
-        for (size_t i = 0; i < pairs.size(); ++i) {
-            n_stage_params.constraints[pairs[i]] = stod(pairs[i + 1]);
+        std::vector<std::string> stages = util::FileIO::Split(n_stage_constraints, ';');
+        for (size_t i = 0; i < stages.size(); ++i)
+        {
+            std::unordered_map<std::string, double> map;
+
+            std::vector<std::string> pairs = util::FileIO::Split(stages[i], ',');
+            for (size_t j = 0; j < pairs.size(); ++j)
+            {
+                map[pairs[j]] = stod(pairs[j + 1]);
+            }
+
+            n_stage_params.constraints.push_back(map);
         }
         }
 
 
-        //TODO set the output file name
+        //TODO set the output file name to better distinguish between different parameter values
 
 
         RunNStage(sequence, tracks);
         RunNStage(sequence, tracks);
     }
     }

+ 0 - 3
util/Filter2D.h

@@ -33,9 +33,6 @@ namespace util
          */
          */
         Filter2D(double multiplier, std::vector<double> mask);
         Filter2D(double multiplier, std::vector<double> mask);
 
 
-        // Example:
-        // mask_string = multiplier, m00, m01, m02, ..., m10, m11, m12, ..., mnn
-        // delimiter = ,
         /**
         /**
          * Creates a new instance by parsing the specified mask string.
          * Creates a new instance by parsing the specified mask string.
          * Values are separated by the specified delimiter.
          * Values are separated by the specified delimiter.