Skip to content

Commit

Permalink
fix: rle compress
Browse files Browse the repository at this point in the history
Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
  • Loading branch information
badai-nguyen committed Jul 9, 2024
1 parent 357ceec commit 3d42d8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
#else
#include <cv_bridge/cv_bridge.h>
#endif
#include <std_msgs/msg/string.hpp>

#include <chrono>
#include <fstream>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

namespace tensorrt_yolox
Expand Down Expand Up @@ -83,8 +83,6 @@ class TrtYoloXNode : public rclcpp::Node
int mapRoiLabel2SegLabel(const int32_t roi_label_index);
image_transport::Publisher image_pub_;
image_transport::Publisher mask_pub_;
// rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr mask_pub_;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr str_pub_;

image_transport::Publisher color_mask_pub_;

Expand Down
8 changes: 3 additions & 5 deletions perception/tensorrt_yolox/src/tensorrt_yolox_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ TrtYoloXNode::TrtYoloXNode(const rclcpp::NodeOptions & node_options)
mask_pub_ = image_transport::create_publisher(this, "~/out/mask");
color_mask_pub_ = image_transport::create_publisher(this, "~/out/color_mask");
image_pub_ = image_transport::create_publisher(this, "~/out/image");
str_pub_ = this->create_publisher<std_msgs::msg::String>("~/out/mask_string", 10);

if (declare_parameter("build_only", false)) {
RCLCPP_INFO(this->get_logger(), "TensorRT engine file is built and exit.");
Expand Down Expand Up @@ -236,7 +235,7 @@ void TrtYoloXNode::onImage(const sensor_msgs::msg::Image::ConstSharedPtr msg)
overlapSegmentByRoi(yolox_object, mask, width, height);
}
}
// TODO(badai-nguyen): consider to change to 4bits data transfer
// Compress mask to RLE format
if (trt_yolox_->getMultitaskNum() > 0) {
sensor_msgs::msg::Image::SharedPtr out_mask_msg =
cv_bridge::CvImage(std_msgs::msg::Header(), sensor_msgs::image_encodings::MONO8, mask)
Expand All @@ -247,12 +246,11 @@ void TrtYoloXNode::onImage(const sensor_msgs::msg::Image::ConstSharedPtr msg)
int step = sizeof(uint8_t) + sizeof(int);
out_mask_msg->data.resize(static_cast<int>(compressed_data.size()) * step);
for (size_t i = 0; i < compressed_data.size(); ++i) {
std::memcpy(&compressed_data.at(i).first, &out_mask_msg->data[i * step], sizeof(uint8_t));
std::memcpy(&out_mask_msg->data[i * step], &compressed_data.at(i).first, sizeof(uint8_t));
std::memcpy(
&compressed_data.at(i).second, &out_mask_msg->data[i * step + sizeof(uint8_t)],
&out_mask_msg->data[i * step + sizeof(uint8_t)], &compressed_data.at(i).second,
sizeof(int));
}

Check warning on line 253 in perception/tensorrt_yolox/src/tensorrt_yolox_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

TrtYoloXNode::onImage increases in cyclomatic complexity from 10 to 11, 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 253 in perception/tensorrt_yolox/src/tensorrt_yolox_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

TrtYoloXNode::onImage 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.
out_mask_msg->step = step;
mask_pub_.publish(out_mask_msg);
}
image_pub_.publish(in_image_ptr->toImageMsg());
Expand Down

0 comments on commit 3d42d8b

Please sign in to comment.