소스 검색

improved visualization

Helge Wrede 8 년 전
부모
커밋
6b855a0d0c
11개의 변경된 파일51개의 추가작업 그리고 21개의 파일을 삭제
  1. 1 1
      core/ObjectData.cpp
  2. 2 1
      core/ObjectData.h
  3. 4 4
      core/ObjectData2D.cpp
  4. 1 1
      core/ObjectData2D.h
  5. 1 1
      core/ObjectDataAngular.cpp
  6. 1 1
      core/ObjectDataAngular.h
  7. 1 1
      core/ObjectDataBox.cpp
  8. 1 1
      core/ObjectDataBox.h
  9. 29 5
      core/Tracklet.cpp
  10. 3 2
      core/Tracklet.h
  11. 7 3
      util/Visualizer.cpp

+ 1 - 1
core/ObjectData.cpp

@@ -101,7 +101,7 @@ namespace core
         frame_index_ = index;
     }
 
-    void ObjectData::Visualize(cv::Mat& image, cv::Scalar& color) const
+    void ObjectData::Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const
     {
         /* EMPTY */
     }

+ 2 - 1
core/ObjectData.h

@@ -125,8 +125,9 @@ namespace core
          * something.
          * @param image The image to write into
          * @param color The color to use
+         * @param alpha The alpha channel value in the range [0.0, 1.0]
          */
-        virtual void Visualize(cv::Mat& image, cv::Scalar& color) const;
+        virtual void Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const;
 
         /**
          * Overrides the << operator for custom output.

+ 4 - 4
core/ObjectData2D.cpp

@@ -111,11 +111,11 @@ namespace core
            << "y: " << position_.y << "}";
     }
 
-    void ObjectData2D::Visualize(cv::Mat& image, cv::Scalar& color) const
+    void ObjectData2D::Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const
     {
-        double x = position_.x;
-        double y = position_.y;
-        int r = (int) (0.005 * (image.rows + image.cols) * 0.5);
+        double x = position_.x * image.cols;
+        double y = position_.y * image.rows;
+        int r = (int) (0.01 * (image.rows + image.cols) * 0.5);
 
         cv::circle(image, cv::Point2d(x, y), r, color);
     }

+ 1 - 1
core/ObjectData2D.h

@@ -83,7 +83,7 @@ namespace core
                                          std::unordered_map<std::string, double> & constraints)
                 const override;
         virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const override;
-        virtual void Visualize(cv::Mat& image, cv::Scalar& color) const override;
+        virtual void Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const override;
         virtual std::string ToString(char delimiter) const override;
     };
 }

+ 1 - 1
core/ObjectDataAngular.cpp

@@ -96,7 +96,7 @@ namespace core
         return obj_out;
     }
 
-    void ObjectDataAngular::Visualize(cv::Mat& image, cv::Scalar& color) const
+    void ObjectDataAngular::Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const
     {
         double x = GetPosition().x * image.cols;
         double y = GetPosition().y * image.rows;

+ 1 - 1
core/ObjectDataAngular.h

@@ -79,7 +79,7 @@ namespace core
                                          std::unordered_map<std::string, double> & constraints)
                 const override;
         virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const override;
-        virtual void Visualize(cv::Mat& image, cv::Scalar& color) const override;
+        virtual void Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const override;
         virtual std::string ToString(char delimiter) const override;
     };
 }

+ 1 - 1
core/ObjectDataBox.cpp

@@ -91,7 +91,7 @@ namespace core
         return result;
     }
 
-    void ObjectDataBox::Visualize(cv::Mat& image, cv::Scalar& color) const
+    void ObjectDataBox::Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const
     {
         cv::Point2d center(GetPosition().x * image.cols, GetPosition().y * image.rows);
         cv::Point2d size(size_.x * image.cols, size_.y * image.rows);

+ 1 - 1
core/ObjectDataBox.h

@@ -49,7 +49,7 @@ namespace core
                                          std::unordered_map<std::string, double> & constraints)
                 const override;
         virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const override;
-        virtual void Visualize(cv::Mat& image, cv::Scalar& color) const override;
+        virtual void Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const override;
         virtual std::string ToString(char delimiter) const override;
     };
 }

+ 29 - 5
core/Tracklet.cpp

@@ -4,6 +4,8 @@
 
 #include "Tracklet.h"
 #include "../util/Logger.h"
+#include "ObjectData2D.h"
+#include "../util/MyMath.h"
 
 namespace core
 {
@@ -110,17 +112,23 @@ namespace core
         return path_objects_[path_objects_.size() - 1]->Interpolate(tlt->path_objects_[0], fraction);
     }
 
-    void Tracklet::Visualize(cv::Mat& image, cv::Scalar& color) const
+    void Tracklet::Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const
     {
         for (auto obj : path_objects_)
         {
-            obj->Visualize(image, color);
+            obj->Visualize(image, color, alpha);
         }
     }
 
     void Tracklet::Visualize(cv::Mat& image, cv::Scalar& color, size_t frame,
-                             size_t predecessor_count, size_t successor_count) const
+                             size_t predecessor_count, size_t successor_count, bool points) const
     {
+        // Only visualize if the track is currently active
+        if (GetFirstFrameIndex() > frame || GetLastFrameIndex() < frame)
+        {
+            return;
+        }
+
         // Prevent negative values because frame is unsigned
         predecessor_count = std::min(predecessor_count, frame);
 
@@ -131,9 +139,25 @@ namespace core
 
         for (auto obj : path_objects_)
         {
-            if (obj->GetFrameIndex() >= start && obj->GetFrameIndex() <= end)
+            size_t frame_index = obj->GetFrameIndex();
+            if (frame_index >= start && frame_index <= end)
             {
-                obj->Visualize(image, color);
+                cv::Mat overlay;
+                image.copyTo(overlay);
+
+                double alpha = util::MyMath::InverseLerp(start, end, frame_index);
+
+                if (points && frame_index != end)
+                {
+                    ObjectData2DPtr obj_2d = std::static_pointer_cast<ObjectData2D>(obj);
+                    obj_2d->ObjectData2D::Visualize(overlay, color, alpha);
+                }
+                else
+                {
+                    obj->Visualize(overlay, color, alpha);
+                }
+
+                cv::addWeighted(overlay, alpha, image, 1 - alpha, 0, image);
             }
         }
     }

+ 3 - 2
core/Tracklet.h

@@ -93,9 +93,10 @@ namespace core
          *                          before the given frame
          * @param successor_count The number of path objects to visualize after
          *                        the given frame
+         * @param True, if only points should be drawn
          */
         void Visualize(cv::Mat& image, cv::Scalar& color, size_t frame,
-                       size_t predecessor_count, size_t successor_count) const;
+                       size_t predecessor_count, size_t successor_count, bool points) const;
 
         /**
          * Flattens the current tracklet one level.
@@ -125,7 +126,7 @@ namespace core
         virtual bool IsWithinConstraints(ObjectDataPtr obj,
                                          std::unordered_map<std::string, double> & constraints) const override;
         virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const override;
-        virtual void Visualize(cv::Mat& image, cv::Scalar& color) const override;
+        virtual void Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const override;
     };
 }
 

+ 7 - 3
util/Visualizer.cpp

@@ -33,11 +33,15 @@ namespace util
         std::random_device rd;
         std::mt19937 gen(rd());
         //TODO find better colors (more colors)
+        // BGR
         colors.push_back(cv::Scalar(0, 255, 0));
         colors.push_back(cv::Scalar(0, 0, 255));
         colors.push_back(cv::Scalar(0, 255, 255));
         colors.push_back(cv::Scalar(255, 0, 0));
-        for (size_t i = 4; i < tracks.size(); ++i)
+        colors.push_back(cv::Scalar(255, 0, 255));
+        colors.push_back(cv::Scalar(0, 150, 255));
+        colors.push_back(cv::Scalar(150, 0, 255));
+        for (size_t i = 8; i < tracks.size(); ++i)
         {
             // BGR
             cv::Scalar color(std::generate_canonical<double, 10>(gen) * 255,
@@ -56,7 +60,7 @@ 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], frame_offset + i, 0, 0);
+                    tracks[j]->Visualize(image, colors[j], frame_offset + i, 50, 0, true);
                 }
                 cv::imwrite(output_path + "/images/" + image_files[i], image);
             }
@@ -99,7 +103,7 @@ namespace util
                 // Visualize the tracklets
                 for (size_t i = 0; i < tracks.size(); ++i)
                 {
-                    tracks[i]->Visualize(image, colors[i], current_frame + frame_offset, 0, 0);
+                    tracks[i]->Visualize(image, colors[i], current_frame + frame_offset, 50, 0, true);
                 }
 
                 cv::imshow(title, image);