@@ -28,6 +28,10 @@ ObjectPositionExtractorNode::ObjectPositionExtractorNode(const ros::NodeHandle&
2828 nh_.param <double >(" object_separation_distance" , object_separation_distance_, 2 );
2929 nh_.param <int >(" min_pixel_count_for_detection" , min_pixel_count_for_detection_, 10 );
3030 nh_.param <double >(" sigma_coefficient_" , sigma_coefficient_, 2 );
31+ nh_.param <double >(" object_size_min_x" , object_size_min_x_, 0.1 );
32+ nh_.param <double >(" object_size_max_x" , object_size_max_x_, 0.5 );
33+ nh_.param <double >(" object_size_min_y" , object_size_min_y_, 0.1 );
34+ nh_.param <double >(" object_size_max_y" , object_size_max_y_, 0.5 );
3135
3236 // OpenGL parameters
3337 int color_width, color_height;
@@ -133,8 +137,8 @@ void ObjectPositionExtractorNode::depthCallback(const sensor_msgs::Image::ConstP
133137 extractor_->updateProjectionMatrix (
134138 {static_cast <float >(latestColorCameraInfo.K [0 ]), static_cast <float >(latestColorCameraInfo.K [4 ])},
135139 {static_cast <float >(latestColorCameraInfo.K [2 ]), static_cast <float >(latestColorCameraInfo.K [5 ])},
136- {static_cast <float >(cameraInfoMsg->K [0 ]) , static_cast <float >(cameraInfoMsg->K [4 ])},
137- {static_cast <float >(cameraInfoMsg->K [2 ]) , static_cast <float >(cameraInfoMsg->K [5 ])},
140+ {static_cast <float >(cameraInfoMsg->K [0 ]) , static_cast <float >(cameraInfoMsg->K [4 ])},
141+ {static_cast <float >(cameraInfoMsg->K [2 ]) , static_cast <float >(cameraInfoMsg->K [5 ])},
138142 latestDepthToColor_
139143 );
140144
@@ -154,21 +158,23 @@ void ObjectPositionExtractorNode::depthCallback(const sensor_msgs::Image::ConstP
154158 std::vector<ObjectPositionExtractorNode::ObjectCandidate> candidates;
155159 for (auto it = positionOut_.begin <cv::Vec4f>(); it != positionOut_.end <cv::Vec4f>(); ++it)
156160 {
157- auto x = (*it)[0 ];
158- auto y = (*it)[1 ];
159- auto z = (*it)[2 ];
161+ auto x = (*it)[0 ]; //
162+ auto y = (*it)[1 ]; //
163+ auto z = (*it)[2 ]; // accumulated coordinate value
164+ auto w = (*it)[3 ]; // number of accumulated point
160165
161166 // Not detected at this pixel
162- if (x == 0 && y == 0 && z == 0 )
167+ if (w == 0 )
163168 continue ;
164169
165- Eigen::Vector3d point (x, y, z);
170+ Eigen::Vector3d point (x / w, y / w, z / w);
171+ int accumulated_pixel_count = static_cast <int >(std::round (w));
166172
167173 // If this is the first point, just add it to the candidates
168174 if (candidates.size () == 0 )
169175 {
170176 candidates.emplace_back ();
171- candidates[0 ].add (point);
177+ candidates[0 ].add (point, accumulated_pixel_count );
172178 continue ;
173179 }
174180
@@ -181,12 +187,12 @@ void ObjectPositionExtractorNode::depthCallback(const sensor_msgs::Image::ConstP
181187 if (object_separation_distance_ < minDistance)
182188 {
183189 candidates.emplace_back ();
184- candidates[candidates.size () - 1 ].add (point);
190+ candidates[candidates.size () - 1 ].add (point, accumulated_pixel_count );
185191 continue ;
186192 }
187193
188194 // Add the point to the neareset candidate
189- candidates[minIndex].add (point);
195+ candidates[minIndex].add (point, accumulated_pixel_count );
190196 }
191197
192198 // Publish Object Array
@@ -195,14 +201,19 @@ void ObjectPositionExtractorNode::depthCallback(const sensor_msgs::Image::ConstP
195201 {
196202 auto sigma = candidate.variance ();
197203
198- auto count = candidate. count (sigma_coefficient_ * sigma);
199- if (count < min_pixel_count_for_detection_)
204+ // If number of pixel is lower than threshold, skip it
205+ if (candidate. number_of_detected_pixels < min_pixel_count_for_detection_)
200206 continue ;
201207
202- ROS_INFO_STREAM (" detected object (" << count << " /" << candidate.count () << " px)" );
208+ // If the size of the object along the camera direction is too small or too large, skip it
209+ auto candidate_size = candidate.size (sigma_coefficient_ * sigma);
210+ if (candidate_size.x () < object_size_min_x_ || object_size_max_x_ < candidate_size.x () ||
211+ candidate_size.y () < object_size_min_y_ || object_size_max_y_ < candidate_size.y ())
212+ continue ;
213+
214+ ROS_INFO_STREAM (" detected object (" << candidate.number_of_detected_pixels << " px)" );
203215
204216 auto candidate_pose = candidate.mean (sigma_coefficient_ * sigma);
205- auto candidate_size = candidate.size (sigma_coefficient_ * sigma);
206217 geometry_msgs::Pose pose;
207218 {
208219 pose.position .x = candidate_pose.x ();
@@ -229,7 +240,7 @@ void ObjectPositionExtractorNode::depthCallback(const sensor_msgs::Image::ConstP
229240 o.pose = pose;
230241 o.twist = zero_twist;
231242 o.size = size;
232- o.confidence = static_cast < double >(count) / candidate. count () ; // set number of pixels in threshold as confidence
243+ o.confidence = 1.0 ; // TODO
233244
234245 objectArray.objects .push_back (o);
235246 }
0 commit comments