Browse Source

n-stage comparison error fixed

Helge Wrede 8 years ago
parent
commit
1b86a7feda
8 changed files with 119 additions and 100 deletions
  1. 1 1
      CMakeLists.txt
  2. 9 7
      algo/NStage.cpp
  3. 1 1
      core/ObjectData2D.cpp
  4. 9 5
      core/ObjectDataBox.cpp
  5. 4 2
      core/Tracklet.cpp
  6. 21 16
      main/main.cpp
  7. 71 68
      util/Visualizer.cpp
  8. 3 0
      util/Visualizer.h

+ 1 - 1
CMakeLists.txt

@@ -50,4 +50,4 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 
 add_executable(GBMOT ${SOURCE_FILES})
 
-target_link_libraries(GBMOT ${OpenCV_LIBS} ${Boost_LIBRARIES})
+target_link_libraries(GBMOT ${OpenCV_LIBS} ${Boost_LIBRARIES})

+ 9 - 7
algo/NStage.cpp

@@ -76,10 +76,7 @@ namespace algo
                         {
                             double weight = values[u]->CompareTo(values[v]);
 
-                            if (weight < edge_weight_threshold_)
-                            {
-                                boost::add_edge(u, v, weight, graph);
-                            }
+                            boost::add_edge(u, v, weight, graph);
                         }
                     }
                 }
@@ -214,9 +211,14 @@ namespace algo
                         // 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);
+                            double weight = u_ptr->CompareTo(v_ptr);
+
+                            if (weight < edge_weight_threshold_)
+                            {
+                                boost::add_edge(u, v,
+                                                weight,
+                                                tlt_graph);
+                            }
                         }
                     }
                 }

+ 1 - 1
core/ObjectData2D.cpp

@@ -48,7 +48,7 @@ namespace core
     {
         ObjectData2DPtr obj_2d = std::static_pointer_cast<ObjectData2D>(obj);
 
-        double d_temp = obj_2d->GetFrameIndex() - GetFrameIndex();
+        double d_temp = obj_2d->GetFrameIndex() - GetFrameIndex() - 1;
         double d_spat = util::MyMath::EuclideanDistance(position_, obj_2d->position_);
 
         return d_temp * temporal_weight_ + d_spat * spatial_weight_;

+ 9 - 5
core/ObjectDataBox.cpp

@@ -32,13 +32,17 @@ namespace core
     {
         ObjectDataBoxPtr other = std::static_pointer_cast<ObjectDataBox>(obj);
 
-        cv::Point2d this_center = GetPosition() + size_ * 0.5;
-        cv::Point2d other_center = other->GetPosition() + other->size_ * 0.5;
+//        cv::Point2d this_center = GetPosition() + size_ * 0.5;
+//        cv::Point2d other_center = other->GetPosition() + other->size_ * 0.5;
 
-        double d_temp = other->GetFrameIndex() - GetFrameIndex();
-        double d_spat = util::MyMath::EuclideanDistance(this_center, other_center);
+        double d_temp = other->GetFrameIndex() - GetFrameIndex() - 1;
+        double d_spat = util::MyMath::EuclideanDistance(GetPosition(), other->GetPosition());
 
-        return d_temp * GetTemporalWeight() + d_spat * GetSpatialWeight();
+        double weight = d_temp * GetTemporalWeight() + d_spat * GetSpatialWeight();
+
+//        std::cout << "box weight " << weight << ", t:" << d_temp << ", s:" << d_spat << std::endl;
+
+        return weight;
     }
 
     bool ObjectDataBox::IsWithinConstraints(ObjectDataPtr obj,

+ 4 - 2
core/Tracklet.cpp

@@ -89,6 +89,9 @@ namespace core
     double Tracklet::CompareTo(ObjectDataPtr obj) const
     {
         TrackletPtr tlt = std::static_pointer_cast<Tracklet>(obj);
+        ObjectDataPtr this_obj = path_objects_[path_objects_.size() - 1];
+        ObjectDataPtr that_obj = tlt->path_objects_[0];
+
         return path_objects_[path_objects_.size() - 1]->CompareTo(tlt->path_objects_[0]);
     }
 
@@ -161,8 +164,7 @@ namespace core
 
         for (auto obj : path_objects_)
         {
-            core::TrackletPtr tlt =
-                    std::static_pointer_cast<core::Tracklet>(obj);
+            core::TrackletPtr tlt = std::static_pointer_cast<core::Tracklet>(obj);
 
             for (auto intern_obj : tlt->path_objects_)
             {

+ 21 - 16
main/main.cpp

@@ -391,33 +391,39 @@ void Run(int argc, char const * const * argv)
     // Running the specified algorithm
     std::vector<core::TrackletPtr> tracks;
     time_t begin_time, end_time;
-    std::string output_file_name = algorithm + "_";
+    std::string output_file_name = algorithm;
     util::Logger::LogInfo("Start time measurement");
     begin_time = time(0);
     if (algorithm == "n-stage")
     {
         // Parse the constraints
         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)
+            for (size_t j = 1; j < pairs.size(); ++j)
             {
-                map[pairs[j]] = stod(pairs[j + 1]);
+                map[pairs[j - 1]] = stod(pairs[j]);
             }
 
             n_stage_params.constraints.push_back(map);
         }
 
         //TODO set the output file name to better distinguish between different parameter values
+//        std::vector<std::string> t_counts = util::FileIO::Split(n_stage_params.max_tracklet_count, ',');
+//        for (auto str : t_counts)
+//        {
+//            output_file_name += "_" + str;
+//        }
 
         RunNStage(sequence, tracks);
     }
     else if (algorithm == "berclaz")
     {
-        output_file_name += std::to_string(berclaz_params.h_res) + "x"
+        output_file_name += "_" + std::to_string(berclaz_params.h_res) + "x"
                             + std::to_string(berclaz_params.v_res) + "_"
                             + std::to_string(berclaz_params.vicinity_size) + "_"
                             + std::to_string(berclaz_params.max_track_count) + "_"
@@ -447,18 +453,17 @@ void Run(int argc, char const * const * argv)
     }
 
     // Display the tracking data
-    if (display)
-    {
-        util::Visualizer vis;
+    util::Visualizer vis;
 
-        if (algorithm == "berclaz")
-            vis.Display(tracks, sequence.GetFrameOffset(),
-                        images_folder, output_images, output_path, "Visualizer",
-                        0, 24, show_grid, berclaz_params.h_res, berclaz_params.v_res);
-        else
-            vis.Display(tracks, sequence.GetFrameOffset(),
-                        images_folder, output_images, output_path);
-    }
+    if (algorithm == "berclaz")
+        vis.Display(tracks, sequence.GetFrameOffset(),
+                    images_folder, output_images, display, output_path, "Visualizer",
+                    0, 24, show_grid, berclaz_params.h_res, berclaz_params.v_res);
+    else
+        vis.Display(tracks, sequence.GetFrameOffset(),
+                    images_folder, output_images, display, output_path);
+
+    //TODO add CLEAR-MOT evaluation to pipeline
 }
 
 void CreateTestGraph(DirectedGraph& graph, Vertex& source, Vertex& sink)
@@ -983,4 +988,4 @@ int main(int argc, char const * const * argv)
     Run(argc, argv);
 
     return 0;
-}
+}

+ 71 - 68
util/Visualizer.cpp

@@ -16,7 +16,7 @@ namespace util
     }
 
     void Visualizer::Display(std::vector<core::TrackletPtr> & tracks, size_t frame_offset,
-                             std::string image_folder, bool output,
+                             std::string image_folder, bool output, bool display,
                              std::string output_path, std::string title, size_t first_frame,
                              int play_fps, bool show_grid, int grid_width, int grid_height)
     {
@@ -56,100 +56,103 @@ namespace util
                 cv::Mat image = cv::imread(image_folder + "/" + image_files[i], 1);
                 for (size_t j = 0; j < tracks.size(); ++j)
                 {
-                    tracks[j]->Visualize(image, colors[j], i, 0, 0);
+                    tracks[j]->Visualize(image, colors[j], frame_offset + i, 0, 0);
                 }
                 cv::imwrite(output_path + "/images/" + image_files[i], image);
             }
             util::Logger::LogInfo("Finished writing output images");
         }
 
-        // Create window
-        cv::namedWindow(title, CV_WINDOW_AUTOSIZE);
-
-        // Display frames and data
-        int target_delay = 1000 / play_fps;
-        int last_frame_time = GetTime();
-        int current_delay, current_frame_time;
-        bool play = false;
-        while (true)
+        if (display)
         {
-            // Display image
-            cv::Mat image = cv::imread(image_folder + "/" + image_files[current_frame], 1);
+            // Create window
+            cv::namedWindow(title, CV_WINDOW_AUTOSIZE);
 
-            // Draw grid if resolution is specified
-            if (show_grid && grid_width > 0 && grid_height > 0)
+            // Display frames and data
+            int target_delay = 1000 / play_fps;
+            int last_frame_time = GetTime();
+            int current_delay, current_frame_time;
+            bool play = false;
+            while (true)
             {
-                cv::Scalar gridColor(255, 255, 255);
-                double cellWidth = image.cols / grid_width;
-                double cellHeight = image.rows / grid_height;
-                for (int x = 0; x < grid_width; ++x)
+                // Display image
+                cv::Mat image = cv::imread(image_folder + "/" + image_files[current_frame], 1);
+
+                // Draw grid if resolution is specified
+                if (show_grid && grid_width > 0 && grid_height > 0)
                 {
-                    for (int y = 0; y < grid_height; ++y)
+                    cv::Scalar gridColor(255, 255, 255);
+                    double cellWidth = image.cols / grid_width;
+                    double cellHeight = image.rows / grid_height;
+                    for (int x = 0; x < grid_width; ++x)
                     {
-                        cv::rectangle(image,
-                                      cv::Point2d(x * cellWidth, y * cellHeight),
-                                      cv::Point2d((x + 1) * cellWidth, (y + 1) * cellHeight),
-                                      gridColor);
+                        for (int y = 0; y < grid_height; ++y)
+                        {
+                            cv::rectangle(image,
+                                          cv::Point2d(x * cellWidth, y * cellHeight),
+                                          cv::Point2d((x + 1) * cellWidth, (y + 1) * cellHeight),
+                                          gridColor);
+                        }
                     }
                 }
-            }
 
-            // Visualize the tracklets
-            for (size_t i = 0; i < tracks.size(); ++i)
-            {
-                tracks[i]->Visualize(image, colors[i], current_frame + frame_offset, 0, 0);
-            }
+                // Visualize the tracklets
+                for (size_t i = 0; i < tracks.size(); ++i)
+                {
+                    tracks[i]->Visualize(image, colors[i], current_frame + frame_offset, 0, 0);
+                }
 
-            cv::imshow(title, image);
+                cv::imshow(title, image);
 
-            // Get key input
-            int key;
-            if (play)
-            {
-                current_frame_time = GetTime();
-                current_delay = last_frame_time - current_frame_time;
-                if (current_delay < target_delay)
+                // Get key input
+                int key;
+                if (play)
                 {
-                    key = cv::waitKey(target_delay - current_delay);
+                    current_frame_time = GetTime();
+                    current_delay = last_frame_time - current_frame_time;
+                    if (current_delay < target_delay)
+                    {
+                        key = cv::waitKey(target_delay - current_delay);
+                    }
+                    else
+                    {
+                        key = 0;
+                    }
+                    last_frame_time = GetTime();
                 }
                 else
                 {
-                    key = 0;
+                    key = cv::waitKey(0);
                 }
-                last_frame_time = GetTime();
-            }
-            else
-            {
-                key = cv::waitKey(0);
-            }
 
-            // Process key input
-            if (key == 1048678) // F
-            {
-                play = !play;
-            }
-            else if (key == 1048603) // ESC
-            {
-                break;
-            }
-
-            if (play || key == 1048676) // D
-            {
-                if (current_frame < image_files.size() - 1)
+                // Process key input
+                if (key == 1048678) // F
                 {
-                    current_frame++;
+                    play = !play;
                 }
-                else
+                else if (key == 1048603) // ESC
                 {
-                    current_frame = image_files.size() - 1;
-                    play = false;
+                    break;
                 }
-            }
-            else if (key == 1048673) // A
-            {
-                if (current_frame > 0)
+
+                if (play || key == 1048676) // D
                 {
-                    current_frame--;
+                    if (current_frame < image_files.size() - 1)
+                    {
+                        current_frame++;
+                    }
+                    else
+                    {
+                        current_frame = image_files.size() - 1;
+                        play = false;
+                    }
+                }
+                else if (key == 1048673) // A
+                {
+                    if (current_frame > 0)
+                    {
+                        current_frame--;
+                    }
                 }
             }
         }

+ 3 - 0
util/Visualizer.h

@@ -15,6 +15,7 @@
 
 namespace util
 {
+    //TODO split display into one method for window display and one for file visualization
     /**
      * Utility class for visualizing detection sequences or tracks.
      */
@@ -37,6 +38,7 @@ namespace util
          * @param frame_offset The offset of the first frame
          * @param image_folder The images to use
          * @param output If the frames with the visualized tracks should be stored
+         * @param display If a window should be used to display the tracking results
          * @param output_path The path to store the images into (will need an images folder)
          * @param title The window title
          * @param first_frame The frame to start at
@@ -49,6 +51,7 @@ namespace util
                      size_t frame_offset,
                      std::string image_folder,
                      bool output,
+                     bool display,
                      std::string output_path,
                      std::string title = "Visualizer",
                      size_t first_frame = 0,