Skip to content

Commit d848160

Browse files
refactor(tensorrt_yolox): move utils into perception_utils (autowarefoundation#8435)
* chore(tensorrt_yolo): refactor utils Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> * style(pre-commit): autofix * fix: tensorrt_yolox Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> --------- Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 27313d5 commit d848160

File tree

7 files changed

+22
-11
lines changed

7 files changed

+22
-11
lines changed

common/perception_utils/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ find_package(autoware_cmake REQUIRED)
55
autoware_package()
66

77
ament_auto_package()
8+
9+
ament_auto_add_library(${PROJECT_NAME} SHARED
10+
src/run_length_encoder.cpp
11+
)
12+
13+
find_package(OpenCV REQUIRED)
14+
target_link_libraries(${PROJECT_NAME}
15+
${OpenCV_LIBS}
16+
)

perception/tensorrt_yolox/include/tensorrt_yolox/utils.hpp common/perception_utils/include/perception_utils/run_length_encoder.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_
16-
#define AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_
15+
#ifndef PERCEPTION_UTILS__RUN_LENGTH_ENCODER_HPP_
16+
17+
#define PERCEPTION_UTILS__RUN_LENGTH_ENCODER_HPP_
1718
#include <opencv2/opencv.hpp>
1819

1920
#include <utility>
2021
#include <vector>
2122

22-
namespace autoware::tensorrt_yolox
23+
namespace perception_utils
2324
{
2425
std::vector<std::pair<uint8_t, int>> runLengthEncoder(const cv::Mat & mask);
2526
cv::Mat runLengthDecoder(const std::vector<uint8_t> & rle_data, const int rows, const int cols);
26-
} // namespace autoware::tensorrt_yolox
27+
} // namespace perception_utils
2728

28-
#endif // AUTOWARE__TENSORRT_YOLOX__UTILS_HPP_
29+
#endif // PERCEPTION_UTILS__RUN_LENGTH_ENCODER_HPP_

common/perception_utils/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<buildtool_depend>ament_cmake_auto</buildtool_depend>
1313
<buildtool_depend>autoware_cmake</buildtool_depend>
1414

15+
<depend>libopencv-dev</depend>
1516
<depend>rclcpp</depend>
1617

1718
<export>

perception/tensorrt_yolox/src/utils.cpp common/perception_utils/src/run_length_encoder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "autoware/tensorrt_yolox/utils.hpp"
15+
#include "perception_utils/run_length_encoder.hpp"
1616

17-
namespace autoware::tensorrt_yolox
17+
namespace perception_utils
1818
{
1919

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

65-
} // namespace autoware::tensorrt_yolox
65+
} // namespace perception_utils

perception/tensorrt_yolox/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ rclcpp_components_register_node(yolox_single_image_inference_node
8787
)
8888

8989
ament_auto_add_library(${PROJECT_NAME}_node SHARED
90-
src/utils.cpp
9190
src/tensorrt_yolox_node.cpp
9291
)
9392

perception/tensorrt_yolox/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<depend>image_transport</depend>
2525
<depend>libopencv-dev</depend>
2626
<depend>object_recognition_utils</depend>
27+
<depend>perception_utils</depend>
2728
<depend>rclcpp</depend>
2829
<depend>rclcpp_components</depend>
2930
<depend>sensor_msgs</depend>

perception/tensorrt_yolox/src/tensorrt_yolox_node.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
#include "tensorrt_yolox/tensorrt_yolox_node.hpp"
1616

17-
#include "autoware/tensorrt_yolox/utils.hpp"
1817
#include "object_recognition_utils/object_classification.hpp"
18+
#include "perception_utils/run_length_encoder.hpp"
1919

2020
#include <autoware_perception_msgs/msg/object_classification.hpp>
2121

@@ -223,7 +223,7 @@ void TrtYoloXNode::onImage(const sensor_msgs::msg::Image::ConstSharedPtr msg)
223223
.toImageMsg();
224224
out_mask_msg->header = msg->header;
225225

226-
std::vector<std::pair<uint8_t, int>> compressed_data = runLengthEncoder(mask);
226+
std::vector<std::pair<uint8_t, int>> compressed_data = perception_utils::runLengthEncoder(mask);
227227
int step = sizeof(uint8_t) + sizeof(int);
228228
out_mask_msg->data.resize(static_cast<int>(compressed_data.size()) * step);
229229
for (size_t i = 0; i < compressed_data.size(); ++i) {

0 commit comments

Comments
 (0)