Skip to content

Commit

Permalink
refactor: move update camera field of view calculation to preprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
technolojin committed Dec 12, 2024
1 parent 20ce0ba commit acd27c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class PointPaintingFusionNode
rclcpp::Publisher<DetectedObjects>::SharedPtr obj_pub_ptr_;

// horizontal field of view
std::vector<double> tan_h_left_;
std::vector<double> tan_h_right_;
std::vector<double> fov_left_;
std::vector<double> fov_right_;

int omp_num_threads_{1};
float score_threshold_{0.0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ PointPaintingFusionNode::PointPaintingFusionNode(const rclcpp::NodeOptions & opt
sub_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
"~/input/pointcloud", rclcpp::SensorDataQoS().keep_last(3), sub_callback);

tan_h_left_.resize(rois_number_);
tan_h_right_.resize(rois_number_);
fov_left_.resize(rois_number_);
fov_right_.resize(rois_number_);

Check warning on line 163 in perception/autoware_image_projection_based_fusion/src/pointpainting_fusion/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_image_projection_based_fusion/src/pointpainting_fusion/node.cpp#L162-L163

Added lines #L162 - L163 were not covered by tests
for (std::size_t roi_i = 0; roi_i < rois_number_; ++roi_i) {
tan_h_left_[roi_i] = 0;
tan_h_right_[roi_i] = 0;
fov_left_[roi_i] = 0;
fov_right_[roi_i] = 0;

Check warning on line 166 in perception/autoware_image_projection_based_fusion/src/pointpainting_fusion/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_image_projection_based_fusion/src/pointpainting_fusion/node.cpp#L165-L166

Added lines #L165 - L166 were not covered by tests
}

detection_class_remapper_.setParameters(
Expand Down Expand Up @@ -251,6 +251,15 @@ void PointPaintingFusionNode::preprocess(sensor_msgs::msg::PointCloud2 & painted
painted_pointcloud_msg.point_step);
painted_pointcloud_msg.row_step =
static_cast<uint32_t>(painted_pointcloud_msg.data.size() / painted_pointcloud_msg.height);

// update camera fov
for (std::size_t roi_i = 0; roi_i < rois_number_; ++roi_i) {
const auto fx = camera_info_map_[roi_i].k.at(0);
const auto x0 = camera_info_map_[roi_i].k.at(2);
const auto width = camera_info_map_[roi_i].width;
fov_left_[roi_i] = -x0 / fx;
fov_right_[roi_i] = (-x0 + width) / fx;

Check warning on line 261 in perception/autoware_image_projection_based_fusion/src/pointpainting_fusion/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_image_projection_based_fusion/src/pointpainting_fusion/node.cpp#L257-L261

Added lines #L257 - L261 were not covered by tests
}

Check notice on line 262 in perception/autoware_image_projection_based_fusion/src/pointpainting_fusion/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Complex Method

PointPaintingFusionNode::preprocess increases in cyclomatic complexity from 9 to 10, 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.
}

void PointPaintingFusionNode::fuseOnSingleImage(
Expand All @@ -273,15 +282,6 @@ void PointPaintingFusionNode::fuseOnSingleImage(

if (!checkCameraInfo(camera_info)) return;

// update camera fov
for (std::size_t roi_i = 0; roi_i < rois_number_; ++roi_i) {
const auto fx = camera_info_map_[roi_i].k.at(0);
const auto x0 = camera_info_map_[roi_i].k.at(2);
const auto width = camera_info_map_[roi_i].width;
tan_h_left_[roi_i] = (x0-width) / fx;
tan_h_right_[roi_i] = x0 / fx;
}

std::vector<sensor_msgs::msg::RegionOfInterest> debug_image_rois;
std::vector<Eigen::Vector2d> debug_image_points;

Expand Down Expand Up @@ -349,8 +349,8 @@ dc | dc dc dc dc ||zc|

/// check if the point is in the camera view
if (p_z <= 0.0) continue;
if (p_x < tan_h_left_.at(image_id) * p_z) continue;
if ( p_x > tan_h_right_.at(image_id) * p_z)continue;
if (p_x < fov_left_.at(image_id) * p_z) continue;
if (p_x > fov_right_.at(image_id) * p_z) continue;

// project
Eigen::Vector2d projected_point = calcRawImageProjectedPoint(
Expand Down

0 comments on commit acd27c5

Please sign in to comment.