Skip to content

Commit 4d0397a

Browse files
author
KhalilSelyan
committed
fix colors, proba position/precision, text into shapes
Signed-off-by: KhalilSelyan <khalil@leodrive.ai>
1 parent 8406008 commit 4d0397a

File tree

1 file changed

+26
-10
lines changed
  • perception/traffic_light_visualization/src/traffic_light_roi_visualizer

1 file changed

+26
-10
lines changed

perception/traffic_light_visualization/src/traffic_light_roi_visualizer/nodelet.cpp

+26-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "traffic_light_visualization/traffic_light_roi_visualizer/nodelet.hpp" // NOLINT(whitespace/line_length)
1616

17+
#include "traffic_light_visualization/traffic_light_roi_visualizer/shape_draw.hpp" // NOLINT(whitespace/line_length)
18+
1719
#include <rclcpp/rclcpp.hpp>
1820
#include <rclcpp_components/register_node_macro.hpp>
1921

@@ -95,9 +97,9 @@ bool TrafficLightRoiVisualizerNodelet::createRect(
9597
if (result.label.find("red") != std::string::npos) {
9698
color = cv::Scalar{255, 0, 0};
9799
} else if (result.label.find("yellow") != std::string::npos) {
98-
color = cv::Scalar{0, 255, 0};
100+
color = cv::Scalar{255, 255, 0};
99101
} else if (result.label.find("green") != std::string::npos) {
100-
color = cv::Scalar{0, 0, 255};
102+
color = cv::Scalar{0, 255, 0};
101103
} else {
102104
color = cv::Scalar{255, 255, 255};
103105
}
@@ -107,15 +109,29 @@ bool TrafficLightRoiVisualizerNodelet::createRect(
107109
cv::Point(tl_roi.roi.x_offset + tl_roi.roi.width, tl_roi.roi.y_offset + tl_roi.roi.height),
108110
color, 3);
109111

110-
int offset = 40;
112+
int y_offset = 10;
113+
int x_offset = 15;
111114
cv::putText(
112-
image, std::to_string(result.prob),
113-
cv::Point(tl_roi.roi.x_offset, tl_roi.roi.y_offset - (offset * 0)), cv::FONT_HERSHEY_COMPLEX,
114-
1.1, color, 3);
115-
116-
cv::putText(
117-
image, result.label, cv::Point(tl_roi.roi.x_offset, tl_roi.roi.y_offset - (offset * 1)),
118-
cv::FONT_HERSHEY_COMPLEX, 1.1, color, 2);
115+
image, std::to_string(static_cast<int>(round(result.prob * 100))),
116+
cv::Point(
117+
tl_roi.roi.x_offset + tl_roi.roi.width + (x_offset * 0.5),
118+
tl_roi.roi.y_offset + (y_offset * 0.75)),
119+
cv::FONT_HERSHEY_COMPLEX, 0.5, color, 2);
120+
121+
std::string shape_name = result.label.find('-') != std::string::npos
122+
? result.label.substr(result.label.find('-') + 1)
123+
: "unknown";
124+
125+
if (shape_name != "unknown") {
126+
drawTrafficLightShape(
127+
image, shape_name, cv::Point(tl_roi.roi.x_offset + (x_offset * 1), tl_roi.roi.y_offset),
128+
color, 16);
129+
} else {
130+
cv::putText(
131+
image, shape_name,
132+
cv::Point(tl_roi.roi.x_offset + (x_offset * 0), tl_roi.roi.y_offset - (y_offset * 0.75)),
133+
cv::FONT_HERSHEY_COMPLEX, 0.5, color, 2);
134+
}
119135

120136
return true;
121137
}

0 commit comments

Comments
 (0)