Skip to content

Commit effe347

Browse files
authored
fix(roi_pointcloud_fusion): add roi scale factor param (#10333)
* fix(roi_pointcloud_fusion): add roi scale factor param Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * fix: missing declare Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> --------- Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
1 parent fb43046 commit effe347

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

perception/autoware_image_projection_based_fusion/config/roi_pointcloud_fusion.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
min_cluster_size: 2
55
max_cluster_size: 20
66
cluster_2d_tolerance: 0.5
7+
roi_scale_factor: 1.0

perception/autoware_image_projection_based_fusion/include/autoware/image_projection_based_fusion/roi_pointcloud_fusion/node.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class RoiPointCloudFusionNode : public FusionNode<PointCloudMsgType, RoiMsgType,
4646
int max_cluster_size_{20};
4747
bool fuse_unknown_only_{true};
4848
double cluster_2d_tolerance_;
49+
double roi_scale_factor_{1.0};
4950

5051
std::vector<ClusterObjType> output_fused_objects_;
5152
};

perception/autoware_image_projection_based_fusion/include/autoware/image_projection_based_fusion/utils/geometry.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ bool is_inside(
6464
const sensor_msgs::msg::RegionOfInterest & outer,
6565
const sensor_msgs::msg::RegionOfInterest & inner, const double outer_offset_scale = 1.1);
6666

67+
bool isPointInsideRoi(
68+
const sensor_msgs::msg::RegionOfInterest & roi, const double camera_point_x,
69+
const double camera_point_y, const double roi_scale_factor);
70+
6771
void sanitizeROI(sensor_msgs::msg::RegionOfInterest & roi, const int width, const int height);
6872

6973
} // namespace autoware::image_projection_based_fusion

perception/autoware_image_projection_based_fusion/schema/roi_pointcloud_fusion.schema.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,20 @@
2626
"description": "A cluster tolerance measured in radial direction [m]",
2727
"default": 0.5,
2828
"exclusiveMinimum": 0.0
29+
},
30+
"roi_scale_factor": {
31+
"type": "number",
32+
"description": "A scale factor for resizing RoI while checking if points are inside the RoI.",
33+
"default": 1.0,
34+
"exclusiveMinimum": 0.0
2935
}
3036
},
31-
"required": ["fuse_unknown_only", "min_cluster_size", "cluster_2d_tolerance"]
37+
"required": [
38+
"fuse_unknown_only",
39+
"min_cluster_size",
40+
"cluster_2d_tolerance",
41+
"roi_scale_factor"
42+
]
3243
}
3344
},
3445
"properties": {

perception/autoware_image_projection_based_fusion/src/roi_pointcloud_fusion/node.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ RoiPointCloudFusionNode::RoiPointCloudFusionNode(const rclcpp::NodeOptions & opt
4343
min_cluster_size_ = declare_parameter<int>("min_cluster_size");
4444
max_cluster_size_ = declare_parameter<int>("max_cluster_size");
4545
cluster_2d_tolerance_ = declare_parameter<double>("cluster_2d_tolerance");
46+
roi_scale_factor_ = declare_parameter<double>("roi_scale_factor");
4647

4748
// publisher
4849
pub_ptr_ = this->create_publisher<ClusterMsgType>("output", rclcpp::QoS{1});
@@ -149,10 +150,7 @@ void RoiPointCloudFusionNode::fuse_on_single_image(
149150
static_cast<size_t>(max_cluster_size_) * static_cast<size_t>(point_step)) {
150151
continue;
151152
}
152-
if (
153-
check_roi.x_offset <= px && check_roi.y_offset <= py &&
154-
check_roi.x_offset + check_roi.width >= px &&
155-
check_roi.y_offset + check_roi.height >= py) {
153+
if (isPointInsideRoi(check_roi, px, py, roi_scale_factor_)) {
156154
std::memcpy(
157155
&cluster.data[clusters_data_size.at(i)], &input_pointcloud_msg.data[offset],
158156
point_step);

perception/autoware_image_projection_based_fusion/src/utils/geometry.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ bool is_inside(
187187
}
188188
return true;
189189
}
190+
bool isPointInsideRoi(
191+
const sensor_msgs::msg::RegionOfInterest & roi, const double camera_point_x,
192+
const double camera_point_y, const double roi_scale_factor)
193+
{
194+
const auto scaled_width = static_cast<double>(roi.width) * roi_scale_factor;
195+
const auto scaled_heigh = static_cast<double>(roi.height) * roi_scale_factor;
196+
const auto scaled_x_offset = static_cast<double>(roi.x_offset) - (scaled_width - roi.width) / 2.0;
197+
const auto scaled_y_offset =
198+
static_cast<double>(roi.y_offset) - (scaled_heigh - roi.height) / 2.0;
199+
if (
200+
scaled_x_offset <= camera_point_x && scaled_y_offset <= camera_point_y &&
201+
scaled_x_offset + scaled_width >= camera_point_x &&
202+
scaled_y_offset + scaled_heigh >= camera_point_y) {
203+
return true;
204+
}
205+
return false;
206+
}
190207

191208
void sanitizeROI(sensor_msgs::msg::RegionOfInterest & roi, const int width_, const int height_)
192209
{

0 commit comments

Comments
 (0)