32
32
#include < map>
33
33
#include < memory>
34
34
#include < mutex>
35
+ #include < sstream>
35
36
#include < string>
37
+ #include < vector>
36
38
37
39
namespace traffic_light
38
40
{
@@ -42,7 +44,16 @@ struct ClassificationResult
42
44
std::string label;
43
45
};
44
46
45
- class TrafficLightRoiVisualizerNodelet : public rclcpp ::Node
47
+ /* *
48
+ * @brief A struct to represent parsed traffic light shape information.
49
+ */
50
+ struct TrafficLightShapeInfo
51
+ {
52
+ cv::Scalar color; // !< Color associated with "circle".
53
+ std::vector<std::string> shapes; // !< Shape names.
54
+ };
55
+
56
+ class TrafficLightRoiVisualizerNode : public rclcpp ::Node
46
57
{
47
58
public:
48
59
explicit TrafficLightRoiVisualizerNodelet (const rclcpp::NodeOptions & options);
@@ -74,13 +85,59 @@ class TrafficLightRoiVisualizerNodelet : public rclcpp::Node
74
85
{tier4_perception_msgs::msg::TrafficLightElement::RIGHT_ARROW, " right" },
75
86
{tier4_perception_msgs::msg::TrafficLightElement::UP_ARROW, " straight" },
76
87
{tier4_perception_msgs::msg::TrafficLightElement::DOWN_ARROW, " down" },
88
+ {tier4_perception_msgs::msg::TrafficLightElement::UP_LEFT_ARROW, " straight_left" },
89
+ {tier4_perception_msgs::msg::TrafficLightElement::UP_RIGHT_ARROW, " straight_right" },
77
90
{tier4_perception_msgs::msg::TrafficLightElement::DOWN_LEFT_ARROW, " down_left" },
78
91
{tier4_perception_msgs::msg::TrafficLightElement::DOWN_RIGHT_ARROW, " down_right" },
79
92
{tier4_perception_msgs::msg::TrafficLightElement::CROSS, " cross" },
80
93
// other
81
94
{tier4_perception_msgs::msg::TrafficLightElement::UNKNOWN, " unknown" },
82
95
};
83
96
97
+ /* *
98
+ * @brief Return RGB color from color string associated with "circle".
99
+ * @param color Color string.
100
+ * @return RGB color.
101
+ */
102
+ static cv::Scalar strToColor (const std::string & color)
103
+ {
104
+ if (color == " red" ) {
105
+ return {254 , 149 , 149 };
106
+ } else if (color == " yellow" ) {
107
+ return {254 , 250 , 149 };
108
+ } else if (color == " green" ) {
109
+ return {149 , 254 , 161 };
110
+ } else {
111
+ return {250 , 250 , 250 };
112
+ }
113
+ }
114
+
115
+ /* *
116
+ * @brief Extract color and shape names from label.
117
+ * @param label String formatted as `<Color0>-<Shape0>,<Color1>-<Shape1>,...,<ColorN>-<ShapeN>`.
118
+ * @return Extracted information includes a color associated with "circle" and shape names.
119
+ */
120
+ static TrafficLightShapeInfo extractShapeInfo (const std::string & label)
121
+ {
122
+ cv::Scalar color{255 , 255 , 255 };
123
+ std::vector<std::string> shapes;
124
+
125
+ std::stringstream ss (label);
126
+ std::string segment;
127
+ while (std::getline (ss, segment, ' ,' )) {
128
+ size_t hyphen_pos = segment.find (' -' );
129
+ if (hyphen_pos != std::string::npos) {
130
+ auto shape = segment.substr (hyphen_pos + 1 );
131
+ if (shape == " circle" ) {
132
+ const auto color_str = segment.substr (0 , hyphen_pos);
133
+ color = strToColor (color_str);
134
+ }
135
+ shapes.emplace_back (shape);
136
+ }
137
+ }
138
+ return {color, shapes};
139
+ }
140
+
84
141
bool createRect (
85
142
cv::Mat & image, const tier4_perception_msgs::msg::TrafficLightRoi & tl_roi,
86
143
const cv::Scalar & color);
0 commit comments