Skip to content

Commit

Permalink
refactor(tensorrt_yolox): move utils into perception_utils (autowaref…
Browse files Browse the repository at this point in the history
…oundation#8435)

* chore(tensorrt_yolo): refactor utils

Signed-off-by: badai-nguyen <[email protected]>

* style(pre-commit): autofix

* fix: tensorrt_yolox

Signed-off-by: badai-nguyen <[email protected]>

---------

Signed-off-by: badai-nguyen <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
badai-nguyen and pre-commit-ci[bot] authored Aug 15, 2024
1 parent 9fa7cc9 commit fb76734
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
9 changes: 9 additions & 0 deletions common/perception_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_package()

ament_auto_add_library(${PROJECT_NAME} SHARED
src/run_length_encoder.cpp
)

find_package(OpenCV REQUIRED)
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_
#define AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_
#ifndef PERCEPTION_UTILS__RUN_LENGTH_ENCODER_HPP_

#define PERCEPTION_UTILS__RUN_LENGTH_ENCODER_HPP_
#include <opencv2/opencv.hpp>

#include <utility>
#include <vector>

namespace autoware::tensorrt_yolox
namespace perception_utils
{
std::vector<std::pair<uint8_t, int>> runLengthEncoder(const cv::Mat & mask);
cv::Mat runLengthDecoder(const std::vector<uint8_t> & rle_data, const int rows, const int cols);
} // namespace autoware::tensorrt_yolox
} // namespace perception_utils

#endif // AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_
#endif // PERCEPTION_UTILS__RUN_LENGTH_ENCODER_HPP_
1 change: 1 addition & 0 deletions common/perception_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>libopencv-dev</depend>
<depend>rclcpp</depend>

<export>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware/tensorrt_yolox/utils.hpp"
#include "perception_utils/run_length_encoder.hpp"

namespace autoware::tensorrt_yolox
namespace perception_utils
{

std::vector<std::pair<uint8_t, int>> runLengthEncoder(const cv::Mat & image)
Expand Down Expand Up @@ -62,4 +62,4 @@ cv::Mat runLengthDecoder(const std::vector<uint8_t> & rle_data, const int rows,
return mask;
}

} // namespace autoware::tensorrt_yolox
} // namespace perception_utils
1 change: 0 additions & 1 deletion perception/autoware_tensorrt_yolox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ rclcpp_components_register_node(yolox_single_image_inference_node
)

ament_auto_add_library(${PROJECT_NAME}_node SHARED
src/utils.cpp
src/tensorrt_yolox_node.cpp
)

Expand Down
1 change: 1 addition & 0 deletions perception/autoware_tensorrt_yolox/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<depend>image_transport</depend>
<depend>libopencv-dev</depend>
<depend>object_recognition_utils</depend>
<depend>perception_utils</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>sensor_msgs</depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "autoware/tensorrt_yolox/tensorrt_yolox_node.hpp"

#include "autoware/tensorrt_yolox/utils.hpp"
#include "object_recognition_utils/object_classification.hpp"
#include "perception_utils/run_length_encoder.hpp"

#include <autoware_perception_msgs/msg/object_classification.hpp>

Expand Down Expand Up @@ -184,7 +184,7 @@ void TrtYoloXNode::onImage(const sensor_msgs::msg::Image::ConstSharedPtr msg)
.toImageMsg();
out_mask_msg->header = msg->header;

std::vector<std::pair<uint8_t, int>> compressed_data = runLengthEncoder(mask);
std::vector<std::pair<uint8_t, int>> compressed_data = perception_utils::runLengthEncoder(mask);
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) {
Expand Down

0 comments on commit fb76734

Please sign in to comment.