Kaynağa Gözat

add difference color

leon 1 ay önce
ebeveyn
işleme
848ab035ef
1 değiştirilmiş dosya ile 12 ekleme ve 3 silme
  1. 12 3
      src/nodes/draw/drawNode.cpp

+ 12 - 3
src/nodes/draw/drawNode.cpp

@@ -4,7 +4,7 @@
 #include "nodes/draw/position.hpp"
 #include <opencv2/opencv.hpp>
 #include <chrono>
-
+#include <tuple>
 
 namespace GNode
 {
@@ -17,6 +17,13 @@ static std::tuple<int, int, int> getFontSize(const std::string& text)
     return std::make_tuple(textSize.width, textSize.height, baseline);
 }
 
+static std::tuple<uint8_t, uint8_t, uint8_t> random_color(int id) 
+{
+    float h_plane = ((((unsigned int)id << 2) ^ 0x937151) % 100) / 100.0f;
+    float s_plane = ((((unsigned int)id << 3) ^ 0x315793) % 100) / 100.0f;
+    return hsv2bgr(h_plane, s_plane, 1);
+}
+
 void DrawNode::work() 
 {
     printf("DrawNode %s\n", name_.c_str());
@@ -38,7 +45,9 @@ void DrawNode::work()
             PositionManager<float> pm(getFontSize);
             for (auto& box : metaData->boxes)
             {
-                cv::rectangle(image, cv::Point(box.left, box.top), cv::Point(box.right, box.bottom), cv::Scalar(0, 255, 0), 2);
+                uint8_t b, g, r;
+                std::tie(b, g, r) = yolo::random_color(obj.class_label);
+                cv::rectangle(image, cv::Point(box.left, box.top), cv::Point(box.right, box.bottom), cv::Scalar(b, g, r), 2);
 
                 std::tuple<int, int, int, int> pbox = std::make_tuple(box.left, box.top, box.right, box.bottom);
                 int x, y;
@@ -53,7 +62,7 @@ void DrawNode::work()
                 }
                 std::tie(x, y) = pm.selectOptimalPosition(pbox, image_width, image_height, text);
                 
-                cv::putText(image, text, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0), 2);
+                cv::putText(image, text, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(b, g, r), 2);
             }
             metaData->draw_image = image;
             for (auto& output_buffer : output_buffers_)