@@ -52,16 +52,16 @@ FusionNode<Msg3D, Msg2D, ExportObj>::FusionNode(
52
52
: Node(node_name, options), tf_buffer_(this ->get_clock ()), tf_listener_(tf_buffer_)
53
53
{
54
54
// set rois_number
55
- rois_number_ = static_cast < std::size_t >(declare_parameter< int32_t >( " rois_number" ));
56
- if (rois_number_ < 1 ) {
57
- RCLCPP_WARN (
58
- this -> get_logger (), " minimum rois_number is 1. current rois_number is %zu " , rois_number_);
59
- rois_number_ = 1 ;
55
+ const std::size_t rois_number =
56
+ static_cast <std:: size_t >(declare_parameter< int32_t >( " rois_number " ));
57
+ if (rois_number < 1 ) {
58
+ RCLCPP_ERROR (
59
+ this -> get_logger (), " minimum rois_number is 1. current rois_number is %zu " , rois_number) ;
60
60
}
61
- if (rois_number_ > 8 ) {
61
+ if (rois_number > 8 ) {
62
62
RCLCPP_WARN (
63
63
this ->get_logger (),
64
- " Current rois_number is %zu. Large rois number may cause performance issue." , rois_number_ );
64
+ " Current rois_number is %zu. Large rois number may cause performance issue." , rois_number );
65
65
}
66
66
67
67
// Set parameters
@@ -70,10 +70,11 @@ FusionNode<Msg3D, Msg2D, ExportObj>::FusionNode(
70
70
71
71
std::vector<std::string> input_rois_topics;
72
72
std::vector<std::string> input_camera_info_topics;
73
- input_rois_topics.resize (rois_number_);
74
- input_camera_info_topics.resize (rois_number_);
75
73
76
- for (std::size_t roi_i = 0 ; roi_i < rois_number_; ++roi_i) {
74
+ input_rois_topics.resize (rois_number);
75
+ input_camera_info_topics.resize (rois_number);
76
+
77
+ for (std::size_t roi_i = 0 ; roi_i < rois_number; ++roi_i) {
77
78
input_rois_topics.at (roi_i) = declare_parameter<std::string>(
78
79
" input/rois" + std::to_string (roi_i),
79
80
" /perception/object_recognition/detection/rois" + std::to_string (roi_i));
@@ -84,17 +85,17 @@ FusionNode<Msg3D, Msg2D, ExportObj>::FusionNode(
84
85
}
85
86
86
87
// subscribe camera info
87
- camera_info_subs_.resize (rois_number_ );
88
- for (std::size_t roi_i = 0 ; roi_i < rois_number_ ; ++roi_i) {
88
+ camera_info_subs_.resize (rois_number );
89
+ for (std::size_t roi_i = 0 ; roi_i < rois_number ; ++roi_i) {
89
90
std::function<void (const sensor_msgs::msg::CameraInfo::ConstSharedPtr msg)> fnc =
90
91
std::bind (&FusionNode::cameraInfoCallback, this , std::placeholders::_1, roi_i);
91
92
camera_info_subs_.at (roi_i) = this ->create_subscription <sensor_msgs::msg::CameraInfo>(
92
93
input_camera_info_topics.at (roi_i), rclcpp::QoS{1 }.best_effort (), fnc);
93
94
}
94
95
95
96
// subscribe rois
96
- rois_subs_.resize (rois_number_ );
97
- for (std::size_t roi_i = 0 ; roi_i < rois_number_ ; ++roi_i) {
97
+ rois_subs_.resize (rois_number );
98
+ for (std::size_t roi_i = 0 ; roi_i < rois_number ; ++roi_i) {
98
99
std::function<void (const typename Msg2D::ConstSharedPtr msg)> roi_callback =
99
100
std::bind (&FusionNode::roiCallback, this , std::placeholders::_1, roi_i);
100
101
rois_subs_.at (roi_i) = this ->create_subscription <Msg2D>(
@@ -112,49 +113,13 @@ FusionNode<Msg3D, Msg2D, ExportObj>::FusionNode(
112
113
timer_ = rclcpp::create_timer (
113
114
this , get_clock (), period_ns, std::bind (&FusionNode::timer_callback, this ));
114
115
115
- // camera offset settings
116
- std::vector<double > input_offset_ms = declare_parameter<std::vector<double >>(" input_offset_ms" );
117
- if (!input_offset_ms.empty () && rois_number_ > input_offset_ms.size ()) {
118
- throw std::runtime_error (" The number of offsets does not match the number of topics." );
119
- }
116
+ // initialization on each 2d detections
117
+ setDet2DStatus (rois_number);
120
118
121
- // camera projection settings
122
- std::vector<bool > point_project_to_unrectified_image =
123
- declare_parameter<std::vector<bool >>(" point_project_to_unrectified_image" );
124
- if (rois_number_ > point_project_to_unrectified_image.size ()) {
125
- throw std::runtime_error (
126
- " The number of point_project_to_unrectified_image does not match the number of rois topics." );
127
- }
128
- std::vector<bool > approx_camera_projection =
129
- declare_parameter<std::vector<bool >>(" approximate_camera_projection" );
130
- if (rois_number_ != approx_camera_projection.size ()) {
131
- const std::size_t current_size = approx_camera_projection.size ();
132
- RCLCPP_WARN (
133
- this ->get_logger (),
134
- " The number of elements in approximate_camera_projection should be the same as in "
135
- " rois_number. "
136
- " It has %zu elements." ,
137
- current_size);
138
- if (current_size < rois_number_) {
139
- approx_camera_projection.resize (rois_number_);
140
- for (std::size_t i = current_size; i < rois_number_; i++) {
141
- approx_camera_projection.at (i) = true ;
142
- }
143
- }
144
- }
119
+ // parameters for approximation grid
145
120
approx_grid_cell_w_size_ = declare_parameter<float >(" approximation_grid_cell_width" );
146
121
approx_grid_cell_h_size_ = declare_parameter<float >(" approximation_grid_cell_height" );
147
122
148
- // 2d detection status initialization
149
- det2d_list_.resize (rois_number_);
150
- for (std::size_t roi_i = 0 ; roi_i < rois_number_; ++roi_i) {
151
- det2d_list_.at (roi_i).id = roi_i;
152
- det2d_list_.at (roi_i).project_to_unrectified_image =
153
- point_project_to_unrectified_image.at (roi_i);
154
- det2d_list_.at (roi_i).approximate_camera_projection = approx_camera_projection.at (roi_i);
155
- det2d_list_.at (roi_i).input_offset_ms = input_offset_ms.at (roi_i);
156
- }
157
-
158
123
// parameters for out_of_scope filter
159
124
filter_scope_min_x_ = declare_parameter<double >(" filter_scope_min_x" );
160
125
filter_scope_max_x_ = declare_parameter<double >(" filter_scope_max_x" );
@@ -166,16 +131,16 @@ FusionNode<Msg3D, Msg2D, ExportObj>::FusionNode(
166
131
// debugger
167
132
if (declare_parameter (" debug_mode" , false )) {
168
133
std::vector<std::string> input_camera_topics;
169
- input_camera_topics.resize (rois_number_ );
170
- for (std::size_t roi_i = 0 ; roi_i < rois_number_ ; ++roi_i) {
134
+ input_camera_topics.resize (rois_number );
135
+ for (std::size_t roi_i = 0 ; roi_i < rois_number ; ++roi_i) {
171
136
input_camera_topics.at (roi_i) = declare_parameter<std::string>(
172
137
" input/image" + std::to_string (roi_i),
173
138
" /sensing/camera/camera" + std::to_string (roi_i) + " /image_rect_color" );
174
139
}
175
140
std::size_t image_buffer_size =
176
141
static_cast <std::size_t >(declare_parameter<int32_t >(" image_buffer_size" ));
177
142
debugger_ =
178
- std::make_shared<Debugger >(this , rois_number_ , image_buffer_size, input_camera_topics);
143
+ std::make_shared<Debugger >(this , rois_number , image_buffer_size, input_camera_topics);
179
144
}
180
145
181
146
// time keeper
@@ -199,6 +164,52 @@ FusionNode<Msg3D, Msg2D, ExportObj>::FusionNode(
199
164
}
200
165
}
201
166
167
+ template <class Msg3D , class Msg2D , class ExportObj >
168
+ void FusionNode<Msg3D, Msg2D, ExportObj>::setDet2DStatus(std::size_t rois_number)
169
+ {
170
+ // camera offset settings
171
+ std::vector<double > input_offset_ms = declare_parameter<std::vector<double >>(" input_offset_ms" );
172
+ if (!input_offset_ms.empty () && rois_number > input_offset_ms.size ()) {
173
+ throw std::runtime_error (" The number of offsets does not match the number of topics." );
174
+ }
175
+
176
+ // camera projection settings
177
+ std::vector<bool > point_project_to_unrectified_image =
178
+ declare_parameter<std::vector<bool >>(" point_project_to_unrectified_image" );
179
+ if (rois_number > point_project_to_unrectified_image.size ()) {
180
+ throw std::runtime_error (
181
+ " The number of point_project_to_unrectified_image does not match the number of rois "
182
+ " topics." );
183
+ }
184
+ std::vector<bool > approx_camera_projection =
185
+ declare_parameter<std::vector<bool >>(" approximate_camera_projection" );
186
+ if (rois_number != approx_camera_projection.size ()) {
187
+ const std::size_t current_size = approx_camera_projection.size ();
188
+ RCLCPP_WARN (
189
+ get_logger (),
190
+ " The number of elements in approximate_camera_projection should be the same as in "
191
+ " rois_number. "
192
+ " It has %zu elements." ,
193
+ current_size);
194
+ if (current_size < rois_number) {
195
+ approx_camera_projection.resize (rois_number);
196
+ for (std::size_t i = current_size; i < rois_number; i++) {
197
+ approx_camera_projection.at (i) = true ;
198
+ }
199
+ }
200
+ }
201
+
202
+ // 2d detection status initialization
203
+ det2d_list_.resize (rois_number);
204
+ for (std::size_t roi_i = 0 ; roi_i < rois_number; ++roi_i) {
205
+ det2d_list_.at (roi_i).id = roi_i;
206
+ det2d_list_.at (roi_i).project_to_unrectified_image =
207
+ point_project_to_unrectified_image.at (roi_i);
208
+ det2d_list_.at (roi_i).approximate_camera_projection = approx_camera_projection.at (roi_i);
209
+ det2d_list_.at (roi_i).input_offset_ms = input_offset_ms.at (roi_i);
210
+ }
211
+ }
212
+
202
213
template <class Msg3D , class Msg2D , class ExportObj >
203
214
void FusionNode<Msg3D, Msg2D, ExportObj>::cameraInfoCallback(
204
215
const sensor_msgs::msg::CameraInfo::ConstSharedPtr input_camera_info_msg,
0 commit comments