leon пре 1 месец
родитељ
комит
0aba47a60c
1 измењених фајлова са 36 додато и 1 уклоњено
  1. 36 1
      src/nodes/draw/drawNode.cpp

+ 36 - 1
src/nodes/draw/drawNode.cpp

@@ -17,6 +17,41 @@ 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> hsv2bgr(float h, float s, float v) 
+{
+    const int h_i = static_cast<int>(h * 6);
+    const float f = h * 6 - h_i;
+    const float p = v * (1 - s);
+    const float q = v * (1 - f * s);
+    const float t = v * (1 - (1 - f) * s);
+    float r, g, b;
+    switch (h_i) {
+      case 0:
+        r = v, g = t, b = p;
+        break;
+      case 1:
+        r = q, g = v, b = p;
+        break;
+      case 2:
+        r = p, g = v, b = t;
+        break;
+      case 3:
+        r = p, g = q, b = v;
+        break;
+      case 4:
+        r = t, g = p, b = v;
+        break;
+      case 5:
+        r = v, g = p, b = q;
+        break;
+      default:
+        r = 1, g = 1, b = 1;
+        break;
+    }
+    return make_tuple(static_cast<uint8_t>(b * 255), static_cast<uint8_t>(g * 255),
+                      static_cast<uint8_t>(r * 255));
+  }
+
 static std::tuple<uint8_t, uint8_t, uint8_t> random_color(int id) 
 {
     float h_plane = ((((unsigned int)id << 2) ^ 0x937151) % 100) / 100.0f;
@@ -46,7 +81,7 @@ void DrawNode::work()
             for (auto& box : metaData->boxes)
             {
                 uint8_t b, g, r;
-                std::tie(b, g, r) = yolo::random_color(obj.class_label);
+                std::tie(b, g, r) = random_color(box.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);