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): enable to show iou value in roi_cluster_fusion debug image #5541

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -50,6 +50,7 @@ class Debugger
std::vector<RegionOfInterest> image_rois_;
std::vector<RegionOfInterest> obstacle_rois_;
std::vector<Eigen::Vector2d> obstacle_points_;
std::vector<double> max_iou_for_image_rois_;

private:
void imageCallback(
Expand Down
55 changes: 47 additions & 8 deletions perception/image_projection_based_fusion/src/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,68 @@
const boost::circular_buffer<sensor_msgs::msg::Image::ConstSharedPtr> & image_buffer =
image_buffers_.at(image_id);
const image_transport::Publisher & image_pub = image_pubs_.at(image_id);
const bool draw_iou_score =
max_iou_for_image_rois_.size() > 0 && max_iou_for_image_rois_.size() == image_rois_.size();

Check warning on line 88 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L88

Added line #L88 was not covered by tests

for (std::size_t i = 0; i < image_buffer.size(); ++i) {
if (image_buffer.at(i)->header.stamp != stamp) {
continue;
}

auto cv_ptr = cv_bridge::toCvCopy(image_buffer.at(i), image_buffer.at(i)->encoding);

// draw obstacle points
for (const auto & point : obstacle_points_) {
cv::circle(
cv_ptr->image, cv::Point(static_cast<int>(point.x()), static_cast<int>(point.y())), 2,
cv::Scalar(255, 255, 255), 3, 4);
}

// draw rois
const int img_height = static_cast<int>(image_buffer.at(i)->height);
const int img_width = static_cast<int>(image_buffer.at(i)->width);

Check warning on line 105 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L104-L105

Added lines #L104 - L105 were not covered by tests
for (const auto & roi : obstacle_rois_) {
drawRoiOnImage(
cv_ptr->image, roi, image_buffer.at(i)->width, image_buffer.at(i)->height,
cv::Scalar(255, 0, 0));
drawRoiOnImage(cv_ptr->image, roi, img_width, img_height, cv::Scalar(255, 0, 0)); // blue

Check warning on line 107 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L107

Added line #L107 was not covered by tests
}
// TODO(yukke42): show iou_score on image
for (const auto & roi : image_rois_) {
drawRoiOnImage(
cv_ptr->image, roi, image_buffer.at(i)->width, image_buffer.at(i)->height,
cv::Scalar(0, 0, 255));
drawRoiOnImage(cv_ptr->image, roi, img_width, img_height, cv::Scalar(0, 0, 255)); // red

Check warning on line 110 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L110

Added line #L110 was not covered by tests
}

// show iou_score on image
if (draw_iou_score) {
for (auto roi_index = 0; roi_index < static_cast<int>(image_rois_.size()); ++roi_index) {
std::stringstream stream;
stream << std::fixed << std::setprecision(2) << max_iou_for_image_rois_.at(roi_index);

Check warning on line 117 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L114-L117

Added lines #L114 - L117 were not covered by tests
std::string iou_score = stream.str();

// set text position
int baseline = 3;
cv::Size textSize = cv::getTextSize(iou_score, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseline);
const int text_height = static_cast<int>(textSize.height);
const int text_width = static_cast<int>(textSize.width);
int x = image_rois_.at(roi_index).x_offset;
int y = image_rois_.at(roi_index).y_offset; // offset for text

Check warning on line 126 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L121-L126

Added lines #L121 - L126 were not covered by tests
if (y < 0 + text_height)
y = text_height; // if roi is on the top of image, put text on lower left of roi
if (y > img_height - text_height)

Check warning on line 129 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L129

Added line #L129 was not covered by tests
y = img_height -
text_height; // if roi is on the bottom of image, put text on upper left of roi
if (x > img_width - text_width)

Check warning on line 132 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L132

Added line #L132 was not covered by tests
x = img_width - text_width; // if roi is on the right of image, put text on left of roi
if (x < 0) x = 0; // if roi is on the left of image, put text on right of roi

// choice color by iou score
// cv::Scalar color = max_iou_for_image_rois_.at(i) > 0.5 ? cv::Scalar(0, 255, 0) :
// cv::Scalar(0, 0, 255);
cv::Scalar color = cv::Scalar(0, 0, 255); // red

cv::rectangle(
cv_ptr->image, cv::Point(x, y - textSize.height - baseline),
cv::Point(x + textSize.width, y), cv::Scalar(255, 255, 255),

Check warning on line 143 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L141-L143

Added lines #L141 - L143 were not covered by tests
cv::FILLED); // white background
cv::putText(
cv_ptr->image, iou_score, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 0.5, color, 1,

Check warning on line 146 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L145-L146

Added lines #L145 - L146 were not covered by tests
cv::LINE_AA); // text
}

Check warning on line 148 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

Debugger::publishImage has a cyclomatic complexity of 14, 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.

Check warning on line 148 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

Debugger::publishImage has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check warning on line 148 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Deep, Nested Complexity

Debugger::publishImage has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.

Check warning on line 148 in perception/image_projection_based_fusion/src/debugger.cpp

View check run for this annotation

Codecov / codecov/patch

perception/image_projection_based_fusion/src/debugger.cpp#L148

Added line #L148 was not covered by tests
}

image_pub.publish(cv_ptr->toImageMsg());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,24 @@
{
std::vector<sensor_msgs::msg::RegionOfInterest> debug_image_rois;
std::vector<sensor_msgs::msg::RegionOfInterest> debug_pointcloud_rois;
std::vector<double> debug_max_iou_for_image_rois;
std::vector<Eigen::Vector2d> debug_image_points;

Eigen::Matrix4d projection;
projection << camera_info.p.at(0), camera_info.p.at(1), camera_info.p.at(2), camera_info.p.at(3),
camera_info.p.at(4), camera_info.p.at(5), camera_info.p.at(6), camera_info.p.at(7),
camera_info.p.at(8), camera_info.p.at(9), camera_info.p.at(10), camera_info.p.at(11);

// get transform from cluster frame id to camera optical frame id
geometry_msgs::msg::TransformStamped transform_stamped;
{
const auto transform_stamped_optional = getTransformStamped(
tf_buffer_, /*target*/ camera_info.header.frame_id,
/*source*/ input_cluster_msg.header.frame_id, camera_info.header.stamp);
if (!transform_stamped_optional) {
RCLCPP_WARN_STREAM(

Check warning on line 104 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#L104

Added line #L104 was not covered by tests
get_logger(), "Failed to get transform from " << input_cluster_msg.header.frame_id << " to "
<< camera_info.header.frame_id);
return;
}
transform_stamped = transform_stamped_optional.value();
Expand Down Expand Up @@ -232,12 +236,14 @@
}
}
debug_image_rois.push_back(feature_obj.feature.roi);
debug_max_iou_for_image_rois.push_back(max_iou);

Check warning on line 239 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#L239

Added line #L239 was not covered by tests
YoshiRi marked this conversation as resolved.
Show resolved Hide resolved
}

if (debugger_) {
debugger_->image_rois_ = debug_image_rois;
debugger_->obstacle_rois_ = debug_pointcloud_rois;
debugger_->obstacle_points_ = debug_image_points;
debugger_->max_iou_for_image_rois_ = debug_max_iou_for_image_rois;

Check warning on line 246 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 138 to 144. 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 246 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#L246

Added line #L246 was not covered by tests
debugger_->publishImage(image_id, input_roi_msg.header.stamp);
}
}
Expand Down
Loading