14
14
15
15
#include " traffic_light_visualization/traffic_light_roi_visualizer/nodelet.hpp" // NOLINT(whitespace/line_length)
16
16
17
+ #include " traffic_light_visualization/traffic_light_roi_visualizer/shape_draw.hpp" // NOLINT(whitespace/line_length)
18
+
17
19
#include < rclcpp/rclcpp.hpp>
18
20
#include < rclcpp_components/register_node_macro.hpp>
19
21
@@ -95,9 +97,9 @@ bool TrafficLightRoiVisualizerNodelet::createRect(
95
97
if (result.label .find (" red" ) != std::string::npos) {
96
98
color = cv::Scalar{255 , 0 , 0 };
97
99
} else if (result.label .find (" yellow" ) != std::string::npos) {
98
- color = cv::Scalar{0 , 255 , 0 };
100
+ color = cv::Scalar{255 , 255 , 0 };
99
101
} else if (result.label .find (" green" ) != std::string::npos) {
100
- color = cv::Scalar{0 , 0 , 255 };
102
+ color = cv::Scalar{0 , 255 , 0 };
101
103
} else {
102
104
color = cv::Scalar{255 , 255 , 255 };
103
105
}
@@ -107,15 +109,29 @@ bool TrafficLightRoiVisualizerNodelet::createRect(
107
109
cv::Point (tl_roi.roi .x_offset + tl_roi.roi .width , tl_roi.roi .y_offset + tl_roi.roi .height ),
108
110
color, 3 );
109
111
110
- int offset = 40 ;
112
+ int y_offset = 10 ;
113
+ int x_offset = 15 ;
111
114
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
+ }
119
135
120
136
return true ;
121
137
}
0 commit comments