Skip to content

Commit

Permalink
fix: handle projection errors in image fusion nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
  • Loading branch information
technolojin committed Aug 14, 2024
1 parent 6b31cf4 commit 34ee5f6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,16 @@ dc | dc dc dc dc ||zc|
if (p_z <= 0.0 || p_x > (tan_h_.at(image_id) * p_z) || p_x < (-tan_h_.at(image_id) * p_z)) {
continue;
}
// project
Eigen::Vector2d projected_point =
calcRawImageProjectedPoint(pinhole_camera_model, cv::Point3d(p_x, p_y, p_z));

// project, try and catch. if it fails, return
Eigen::Vector2d projected_point;
try {
projected_point =
calcRawImageProjectedPoint(pinhole_camera_model, cv::Point3d(p_x, p_y, p_z));
} catch (const cv::Exception & e) {
RCLCPP_WARN_STREAM(this->get_logger(), "Error in projection: " << e.what());
continue;
}

// iterate 2d bbox
for (const auto & feature_object : objects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ void RoiClusterFusionNode::fuseOnSingleImage(
continue;
}

Eigen::Vector2d projected_point =
calcRawImageProjectedPoint(pinhole_camera_model, cv::Point3d(*iter_x, *iter_y, *iter_z));
// project, try and catch. if it fails, return
Eigen::Vector2d projected_point;
try {
projected_point =
calcRawImageProjectedPoint(pinhole_camera_model, cv::Point3d(*iter_x, *iter_y, *iter_z));
} catch (const std::exception & e) {
RCLCPP_WARN_STREAM(this->get_logger(), "Error in projection: " << e.what());
return;
}

Check warning on line 143 in perception/autoware_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 increases in cyclomatic complexity from 42 to 43, threshold = 9. 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.
if (
0 <= static_cast<int>(projected_point.x()) &&
static_cast<int>(projected_point.x()) <= static_cast<int>(camera_info.width) - 1 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,15 @@ RoiDetectedObjectFusionNode::generateDetectedObjectRoIs(
continue;
}

Eigen::Vector2d proj_point = calcRawImageProjectedPoint(
pinhole_camera_model, cv::Point3d(point.x(), point.y(), point.z()));
// project, try and catch. if it fails, return
Eigen::Vector2d proj_point;
try {
proj_point = calcRawImageProjectedPoint(
pinhole_camera_model, cv::Point3d(point.x(), point.y(), point.z()));
} catch (const std::exception & e) {
RCLCPP_WARN_STREAM(this->get_logger(), "Error in projection: " << e.what());
return object_roi_map;
}

Check warning on line 157 in perception/autoware_image_projection_based_fusion/src/roi_detected_object_fusion/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

RoiDetectedObjectFusionNode::generateDetectedObjectRoIs increases in cyclomatic complexity from 20 to 21, threshold = 9. 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.

min_x = std::min(proj_point.x(), min_x);
min_y = std::min(proj_point.y(), min_y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,17 @@ void RoiPointCloudFusionNode::fuseOnSingleImage(
if (transformed_z <= 0.0) {
continue;
}
Eigen::Vector2d projected_point = calcRawImageProjectedPoint(
pinhole_camera_model, cv::Point3d(transformed_x, transformed_y, transformed_z));

// project, try and catch. if it fails, return
Eigen::Vector2d projected_point;
try {
projected_point = calcRawImageProjectedPoint(
pinhole_camera_model, cv::Point3d(transformed_x, transformed_y, transformed_z));
} catch (const std::exception & e) {
RCLCPP_WARN_STREAM(this->get_logger(), "Error in projection: " << e.what());
return;
}

for (std::size_t i = 0; i < output_objs.size(); ++i) {
auto & feature_obj = output_objs.at(i);
const auto & check_roi = feature_obj.feature.roi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,15 @@ void SegmentPointCloudFusionNode::fuseOnSingleImage(
continue;
}

Eigen::Vector2d projected_point = calcRawImageProjectedPoint(
pinhole_camera_model, cv::Point3d(transformed_x, transformed_y, transformed_z));
// project, try and catch. if it fails, return
Eigen::Vector2d projected_point;
try {
projected_point = calcRawImageProjectedPoint(
pinhole_camera_model, cv::Point3d(transformed_x, transformed_y, transformed_z));
} catch (const std::exception & e) {
RCLCPP_WARN_STREAM(this->get_logger(), "Error in projection: " << e.what());
return;
}

bool is_inside_image = projected_point.x() > 0 && projected_point.x() < camera_info.width &&
projected_point.y() > 0 && projected_point.y() < camera_info.height;
Expand Down

0 comments on commit 34ee5f6

Please sign in to comment.