Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(image_projection_based_fusion): fix iou geometry function #5568

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ bool is_inside(
const sensor_msgs::msg::RegionOfInterest & outer,
const sensor_msgs::msg::RegionOfInterest & inner, const double outer_offset_scale = 1.1);

void sanitizeROI(sensor_msgs::msg::RegionOfInterest & roi, const int width, const int height);

} // namespace image_projection_based_fusion

#endif // IMAGE_PROJECTION_BASED_FUSION__UTILS__GEOMETRY_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,18 @@
double iou(0.0);
bool is_use_non_trust_object_iou_mode = is_far_enough(
input_cluster_msg.feature_objects.at(cluster_map.first), trust_object_distance_);
auto image_roi = feature_obj.feature.roi;
auto cluster_roi = cluster_map.second;
sanitizeROI(image_roi, camera_info.width, camera_info.height);
sanitizeROI(cluster_roi, camera_info.width, camera_info.height);

Check warning on line 183 in perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp#L180-L183

Added lines #L180 - L183 were not covered by tests
if (is_use_non_trust_object_iou_mode || is_roi_label_known) {
iou =
cal_iou_by_mode(cluster_map.second, feature_obj.feature.roi, non_trust_object_iou_mode_);
iou = cal_iou_by_mode(cluster_roi, image_roi, non_trust_object_iou_mode_);

Check warning on line 185 in perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp#L185

Added line #L185 was not covered by tests
} else {
iou = cal_iou_by_mode(cluster_map.second, feature_obj.feature.roi, trust_object_iou_mode_);
iou = cal_iou_by_mode(cluster_roi, image_roi, trust_object_iou_mode_);

Check warning on line 187 in perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp#L187

Added line #L187 was not covered by tests
}

const bool passed_inside_cluster_gate =
only_allow_inside_cluster_
? is_inside(feature_obj.feature.roi, cluster_map.second, roi_scale_factor_)
: true;
only_allow_inside_cluster_ ? is_inside(image_roi, cluster_roi, roi_scale_factor_) : true;

Check warning on line 191 in perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

RoiClusterFusionNode::fuseOnSingleImage already has high cyclomatic complexity, and now it increases in Lines of Code from 136 to 137. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 191 in perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/roi_cluster_fusion/node.cpp#L191

Added line #L191 was not covered by tests
if (max_iou < iou && passed_inside_cluster_gate) {
index = cluster_map.first;
max_iou = iou;
Expand Down
41 changes: 36 additions & 5 deletions perception/image_projection_based_fusion/src/utils/geometry.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 TIER IV, Inc.

Check notice on line 1 in perception/image_projection_based_fusion/src/utils/geometry.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 4.38 to 4.56, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -166,11 +166,42 @@
const sensor_msgs::msg::RegionOfInterest & outer,
const sensor_msgs::msg::RegionOfInterest & inner, const double outer_offset_scale)
{
const double lower_scale = 1.0 - std::abs(outer_offset_scale - 1.0);
return outer.x_offset * lower_scale <= inner.x_offset &&
outer.y_offset * lower_scale <= inner.y_offset &&
inner.x_offset + inner.width <= (outer.x_offset + outer.width) * outer_offset_scale &&
inner.y_offset + inner.height <= (outer.y_offset + outer.height) * outer_offset_scale;
const auto scaled_width = static_cast<double>(outer.width) * outer_offset_scale;
const auto scaled_height = static_cast<double>(outer.height) * outer_offset_scale;
const auto scaled_x_offset =
static_cast<double>(outer.x_offset) - (scaled_width - outer.width) / 2.0;
const auto scaled_y_offset =
static_cast<double>(outer.y_offset) - (scaled_height - outer.height) / 2.0;

Check warning on line 174 in perception/image_projection_based_fusion/src/utils/geometry.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/utils/geometry.cpp#L169-L174

Added lines #L169 - L174 were not covered by tests

// 1. check left-top corner
if (scaled_x_offset > inner.x_offset || scaled_y_offset > inner.y_offset) {

Check warning on line 177 in perception/image_projection_based_fusion/src/utils/geometry.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/utils/geometry.cpp#L177

Added line #L177 was not covered by tests
return false;
}
// 2. check right-bottom corner
if (
scaled_x_offset + scaled_width < inner.x_offset + inner.width ||
scaled_y_offset + scaled_height < inner.y_offset + inner.height) {
return false;

Check warning on line 184 in perception/image_projection_based_fusion/src/utils/geometry.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/utils/geometry.cpp#L181-L184

Added lines #L181 - L184 were not covered by tests
}
return true;
}

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

Check warning on line 189 in perception/image_projection_based_fusion/src/utils/geometry.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/utils/geometry.cpp#L189

Added line #L189 was not covered by tests
{
const unsigned int width = static_cast<unsigned int>(width_);
const unsigned int height = static_cast<unsigned int>(height_);
if (roi.x_offset >= width || roi.y_offset >= height) {
roi.width = 0;
roi.height = 0;
return;

Check warning on line 196 in perception/image_projection_based_fusion/src/utils/geometry.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/utils/geometry.cpp#L191-L196

Added lines #L191 - L196 were not covered by tests
}

if (roi.x_offset + roi.width > width) {
roi.width = width - roi.x_offset;

Check warning on line 200 in perception/image_projection_based_fusion/src/utils/geometry.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/utils/geometry.cpp#L199-L200

Added lines #L199 - L200 were not covered by tests
}
if (roi.y_offset + roi.height > height) {
roi.height = height - roi.y_offset;

Check warning on line 203 in perception/image_projection_based_fusion/src/utils/geometry.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/utils/geometry.cpp#L202-L203

Added lines #L202 - L203 were not covered by tests
}
}

} // namespace image_projection_based_fusion
Loading