├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── model
├── bus.jpg
├── dataset.txt
├── docker
│ └── dockerfile
└── onnx2rknn.py
├── rknpu2_ros
├── CMakeLists.txt
├── README.md
└── package.xml
├── rknpu2_ros_common
├── CMakeLists.txt
├── README.md
├── include
│ └── rknpu2_ros_common
│ │ ├── coco_names.hpp
│ │ ├── drm_func.h
│ │ ├── model_loader.h
│ │ ├── object.hpp
│ │ ├── rga_func.h
│ │ └── utils.hpp
└── package.xml
└── rknpu2_ros_yolov5
├── CMakeLists.txt
├── README.md
├── include
└── rknpu2_ros_yolov5
│ ├── postprocess.hpp
│ ├── rknpu2_yolov5.hpp
│ └── rknpu2_yolov5_node.hpp
├── package.xml
└── src
├── main.cc
├── postprocess.cc
├── postprocess.h
├── rknpu2_yolov5.cpp
└── rknpu2_yolov5_node.cpp
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "rknpu2"]
2 | path = rknpu2
3 | url = https://github.com/rockchip-linux/rknpu2
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2022, fateshelled
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 |
8 | 1. Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | 2. Redistributions in binary form must reproduce the above copyright notice,
12 | this list of conditions and the following disclaimer in the documentation
13 | and/or other materials provided with the distribution.
14 |
15 | 3. Neither the name of the copyright holder nor the names of its
16 | contributors may be used to endorse or promote products derived from
17 | this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rknpu2_ros
2 | ROS2 Inference sample for using Rockchip NPU.
3 |
4 | tested OrangePi5 (RK3588s) Ubuntu 22.04 + ROS2 Humble.
5 |
6 | ## build
7 | ```bash
8 | # clone repository
9 | cd ros2_ws/src
10 | git clone --recursive https://github.com/fateshelled/rknpu2_ros
11 | cd ../
12 |
13 | # build
14 | # TARGET_SOC = RK3588 or RK356X or RV110X
15 | colcon build --symlink-install --packages-up-to rknpu2_ros --cmake-args -D TARGET_SOC=RK3588
16 | ```
17 |
18 | ## run
19 | ```bash
20 | ros2 run v4l2_camera v4l2_camera_node
21 |
22 | ros2 run rknpu2_ros_yolov5 rknpu2_ros_yolov5
23 | ```
24 |
--------------------------------------------------------------------------------
/model/bus.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fateshelled/rknpu2_ros/c44c548c20a5b0b85bd07e2e0b8f4c47c702a5b3/model/bus.jpg
--------------------------------------------------------------------------------
/model/dataset.txt:
--------------------------------------------------------------------------------
1 | bus.jpg
2 |
--------------------------------------------------------------------------------
/model/docker/dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 | ENV DEBIAN_FRONTEND=noninteractive
3 |
4 | RUN apt update && apt upgrade && \
5 | apt install -y wget git python3-dev python3-pip && \
6 | apt -y clean && \
7 | rm -rf /var/lib/apt/lists/*
8 |
9 | WORKDIR /workspace
10 |
11 | RUN wget https://github.com/rockchip-linux/rknn-toolkit2/raw/master/packages/rknn_toolkit2-1.4.0_22dcfef4-cp38-cp38-linux_x86_64.whl &&\
12 | python3 -m pip install -U pip && \
13 | python3 -m pip install numpy==1.19.5 && \
14 | python3 -m pip install rknn_toolkit2-1.4.0_22dcfef4-cp38-cp38-linux_x86_64.whl && \
15 | python3 -m pip install opencv-python-headless && \
16 | rm rknn_toolkit2-1.4.0_22dcfef4-cp38-cp38-linux_x86_64.whl && \
17 | python3 -m pip cache purge
18 |
--------------------------------------------------------------------------------
/model/onnx2rknn.py:
--------------------------------------------------------------------------------
1 |
2 | import os
3 | import argparse
4 | import ast
5 |
6 | from rknn.api import RKNN
7 |
8 | if __name__ == '__main__':
9 |
10 | parser = argparse.ArgumentParser(description='')
11 | parser.add_argument('--onnx_model_path', type=str, required=True, help='onnx model path')
12 | parser.add_argument('--platform', type=str, default="rk3588", help='platform name. Currently support rk3566 / rk3568 / rk3588 / rv1103 / rv1106. default="rk3588"')
13 | parser.add_argument('--output_dir', type=str, default="rknn_models", help='rknn model output directory. default="rknn_models"')
14 | parser.add_argument('--dataset_file', type=str, default="./dataset.txt", help='dataset file path. default="./dataset.txt"')
15 | args = parser.parse_args()
16 |
17 | PLATFORM = args.platform
18 | ONNX_MODEL_PATH = './yolox_s.onnx'
19 | EXP = os.path.splitext(os.path.basename(ONNX_MODEL_PATH))[0]
20 | OUT_DIR = args.output_dir
21 | DATASET = args.dataset_file
22 | RKNN_MODEL_PATH = './{}/{}.rknn'.format(OUT_DIR, EXP)
23 | # OPT_ONNX_MODEL_PATH = './{}/{}_opt.onnx'.format(OUT_DIR, EXP)
24 | MEAN_VALUES = [[0, 0, 0]]
25 | STD_VALUES = [[255, 255, 255]]
26 |
27 | print()
28 | print('--- Convert onnx model to rknn model ---')
29 |
30 | # Create RKNN object
31 | rknn = RKNN(verbose=False)
32 |
33 | # :param mean_values: Channel mean value list.
34 | # :param std_values: Channel std value list.
35 | # :param quantized_dtype: quantize data type, currently support: asymmetric_quantized-8.
36 | # :param quantized_algorithm: currently support: normal, mmse (Min Mean Square Error), kl_divergence.
37 | # :param quantized_method: quantize method, currently support: layer, channel.
38 | # :param target_platform: target chip platform, default is None, means target platform is rk3566. Currently support rk3566 / rk3568 / rk3588 / rv1103 / rv1106.
39 | # :param quant_img_RGB2BGR: whether to do RGB2BGR when load quantize image (jpg/jpeg/png/bmp), default is False.
40 | # :param float_dtype: non quantize data type, currently support: float16, default is float16.
41 | # :param optimization_level: set optimization level, default 3 means use all default optimization options.
42 | # :param custom_string: add custom string information to rknn model, then can query the information at runtime.
43 | # :param remove_weight: generate a slave rknn model which removes conv2d weight, need share weight with rknn model of complete weights.
44 | # :param compress_weight: compress the weights of the model, which can reduce the size of rknn model.
45 | # :param inputs_yuv_fmt: add yuv preprocess at the top of model.
46 | # :param single_core_mode: only for rk3588. single_core_mode=True can reduce the size of rknn model.
47 | rknn.config(mean_values=MEAN_VALUES, std_values=STD_VALUES, target_platform=PLATFORM)
48 |
49 | # Load onnx model
50 | print()
51 | print('--- Loading ONNX model ---')
52 | ret = rknn.load_onnx(ONNX_MODEL_PATH)
53 | if ret == 0:
54 | print("Success")
55 | else:
56 | print('Load onnx model failed!')
57 | exit(ret)
58 |
59 | # # Optimize onnx model
60 | # # Only support onnx model that with 'quantization_annotation' information!
61 | # print()
62 | # print('--- Optimize ONNX model ---')
63 | # ret = rknn.optimize_onnx(ONNX_MODEL_PATH, OPT_ONNX_MODEL_PATH)
64 | # if ret == 0:
65 | # print("Success")
66 | # else:
67 | # print('Failed to optimize onnx model!')
68 |
69 | # Build model
70 | print()
71 | print('--- Building model ---')
72 | ret = rknn.build(do_quantization=True, dataset=DATASET)
73 | if ret == 0:
74 | print("Success")
75 | else:
76 | print('Failed to build rknn model.')
77 | exit(ret)
78 |
79 | # Export rknn model
80 | print()
81 | print('--- Export RKNN model: {} ---'.format(RKNN_MODEL_PATH))
82 | if not os.path.exists(OUT_DIR):
83 | os.makedirs(OUT_DIR)
84 | ret = rknn.export_rknn(RKNN_MODEL_PATH)
85 | if ret == 0:
86 | print("Success")
87 | else:
88 | print('Failed to export rknn model.')
89 | exit(ret)
90 |
91 | # Import Test
92 | print()
93 | print('--- Import Test RKNN model: {} ---'.format(RKNN_MODEL_PATH))
94 | ret = rknn.load_rknn(RKNN_MODEL_PATH)
95 | if ret == 0:
96 | print("Success")
97 | else:
98 | print('Failed to import rknn model.')
99 | exit(ret)
100 |
101 | print('done')
102 |
103 | rknn.release()
104 |
105 |
--------------------------------------------------------------------------------
/rknpu2_ros/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(rknpu2_ros)
3 |
4 | # find dependencies
5 | find_package(ament_cmake REQUIRED)
6 |
7 | ament_package()
8 |
--------------------------------------------------------------------------------
/rknpu2_ros/README.md:
--------------------------------------------------------------------------------
1 | # RKNPU2_ROS
2 | rknpu2_ros metapackage
--------------------------------------------------------------------------------
/rknpu2_ros/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | rknpu2_ros
5 | 0.1.0
6 | rknpu2_ros metapackage
7 | fateshelled
8 | BSD 3-Clause License
9 | fateshelled
10 |
11 | ament_cmake
12 |
13 | rknpu2_ros_common
14 | rknpu2_ros_yolov5
15 |
16 | ament_lint_auto
17 | ament_lint_common
18 |
19 |
20 | ament_cmake
21 |
22 |
23 |
--------------------------------------------------------------------------------
/rknpu2_ros_common/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(rknpu2_ros_common)
3 |
4 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5 | add_compile_options(-Wall -Wextra -Wpedantic)
6 | endif()
7 |
8 | # find dependencies
9 | find_package(ament_cmake REQUIRED)
10 |
11 | # library
12 | add_library(${PROJECT_NAME} INTERFACE)
13 |
14 | target_include_directories(${PROJECT_NAME} INTERFACE
15 | $
16 | $
17 | )
18 |
19 | install(TARGETS ${PROJECT_NAME}
20 | EXPORT export_${PROJECT_NAME}
21 | ARCHIVE DESTINATION lib
22 | LIBRARY DESTINATION lib
23 | RUNTIME DESTINATION bin
24 | INCLUDES DESTINATION include
25 | )
26 |
27 | install(
28 | DIRECTORY include/
29 | DESTINATION include
30 | )
31 |
32 | ament_export_targets(export_${PROJECT_NAME})
33 |
34 | if(BUILD_TESTING)
35 | find_package(ament_lint_auto REQUIRED)
36 | # the following line skips the linter which checks for copyrights
37 | # uncomment the line when a copyright and license is not present in all source files
38 | #set(ament_cmake_copyright_FOUND TRUE)
39 | # the following line skips cpplint (only works in a git repo)
40 | # uncomment the line when this package is not in a git repo
41 | #set(ament_cmake_cpplint_FOUND TRUE)
42 | ament_lint_auto_find_test_dependencies()
43 | endif()
44 |
45 | ament_package()
46 |
--------------------------------------------------------------------------------
/rknpu2_ros_common/README.md:
--------------------------------------------------------------------------------
1 | # RKNPU2_ROS_COMMON
2 |
3 | header only package
4 |
--------------------------------------------------------------------------------
/rknpu2_ros_common/include/rknpu2_ros_common/coco_names.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | namespace rknpu2_ros{
7 | static const std::vector COCO_CLASSES = {
8 | "person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light",
9 | "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow",
10 | "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee",
11 | "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
12 | "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple",
13 | "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch",
14 | "potted plant", "bed", "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard", "cell phone",
15 | "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear",
16 | "hair drier", "toothbrush"
17 | };
18 | const float color_list[80][3] ={
19 | {0.000, 0.447, 0.741},
20 | {0.850, 0.325, 0.098},
21 | {0.929, 0.694, 0.125},
22 | {0.494, 0.184, 0.556},
23 | {0.466, 0.674, 0.188},
24 | {0.301, 0.745, 0.933},
25 | {0.635, 0.078, 0.184},
26 | {0.300, 0.300, 0.300},
27 | {0.600, 0.600, 0.600},
28 | {1.000, 0.000, 0.000},
29 | {1.000, 0.500, 0.000},
30 | {0.749, 0.749, 0.000},
31 | {0.000, 1.000, 0.000},
32 | {0.000, 0.000, 1.000},
33 | {0.667, 0.000, 1.000},
34 | {0.333, 0.333, 0.000},
35 | {0.333, 0.667, 0.000},
36 | {0.333, 1.000, 0.000},
37 | {0.667, 0.333, 0.000},
38 | {0.667, 0.667, 0.000},
39 | {0.667, 1.000, 0.000},
40 | {1.000, 0.333, 0.000},
41 | {1.000, 0.667, 0.000},
42 | {1.000, 1.000, 0.000},
43 | {0.000, 0.333, 0.500},
44 | {0.000, 0.667, 0.500},
45 | {0.000, 1.000, 0.500},
46 | {0.333, 0.000, 0.500},
47 | {0.333, 0.333, 0.500},
48 | {0.333, 0.667, 0.500},
49 | {0.333, 1.000, 0.500},
50 | {0.667, 0.000, 0.500},
51 | {0.667, 0.333, 0.500},
52 | {0.667, 0.667, 0.500},
53 | {0.667, 1.000, 0.500},
54 | {1.000, 0.000, 0.500},
55 | {1.000, 0.333, 0.500},
56 | {1.000, 0.667, 0.500},
57 | {1.000, 1.000, 0.500},
58 | {0.000, 0.333, 1.000},
59 | {0.000, 0.667, 1.000},
60 | {0.000, 1.000, 1.000},
61 | {0.333, 0.000, 1.000},
62 | {0.333, 0.333, 1.000},
63 | {0.333, 0.667, 1.000},
64 | {0.333, 1.000, 1.000},
65 | {0.667, 0.000, 1.000},
66 | {0.667, 0.333, 1.000},
67 | {0.667, 0.667, 1.000},
68 | {0.667, 1.000, 1.000},
69 | {1.000, 0.000, 1.000},
70 | {1.000, 0.333, 1.000},
71 | {1.000, 0.667, 1.000},
72 | {0.333, 0.000, 0.000},
73 | {0.500, 0.000, 0.000},
74 | {0.667, 0.000, 0.000},
75 | {0.833, 0.000, 0.000},
76 | {1.000, 0.000, 0.000},
77 | {0.000, 0.167, 0.000},
78 | {0.000, 0.333, 0.000},
79 | {0.000, 0.500, 0.000},
80 | {0.000, 0.667, 0.000},
81 | {0.000, 0.833, 0.000},
82 | {0.000, 1.000, 0.000},
83 | {0.000, 0.000, 0.167},
84 | {0.000, 0.000, 0.333},
85 | {0.000, 0.000, 0.500},
86 | {0.000, 0.000, 0.667},
87 | {0.000, 0.000, 0.833},
88 | {0.000, 0.000, 1.000},
89 | {0.000, 0.000, 0.000},
90 | {0.143, 0.143, 0.143},
91 | {0.286, 0.286, 0.286},
92 | {0.429, 0.429, 0.429},
93 | {0.571, 0.571, 0.571},
94 | {0.714, 0.714, 0.714},
95 | {0.857, 0.857, 0.857},
96 | {0.000, 0.447, 0.741},
97 | {0.314, 0.717, 0.741},
98 | {0.50, 0.5, 0}
99 | };
100 | }
101 |
--------------------------------------------------------------------------------
/rknpu2_ros_common/include/rknpu2_ros_common/drm_func.h:
--------------------------------------------------------------------------------
1 | #ifndef __DRM_FUNC_H__
2 | #define __DRM_FUNC_H__
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include // open function
8 | #include // close function
9 | #include
10 | #include
11 |
12 |
13 | #include
14 | #include "libdrm/drm_fourcc.h"
15 | #include "xf86drm.h"
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | typedef int (* FUNC_DRM_IOCTL)(int fd, unsigned long request, void *arg);
22 |
23 | typedef struct _drm_context{
24 | void *drm_handle;
25 | FUNC_DRM_IOCTL io_func;
26 | } drm_context;
27 |
28 | /* memory type definitions. */
29 | enum drm_rockchip_gem_mem_type
30 | {
31 | /* Physically Continuous memory and used as default. */
32 | ROCKCHIP_BO_CONTIG = 1 << 0,
33 | /* cachable mapping. */
34 | ROCKCHIP_BO_CACHABLE = 1 << 1,
35 | /* write-combine mapping. */
36 | ROCKCHIP_BO_WC = 1 << 2,
37 | ROCKCHIP_BO_SECURE = 1 << 3,
38 | ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE |
39 | ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE
40 | };
41 |
42 | int drm_init(drm_context *drm_ctx);
43 |
44 | void* drm_buf_alloc(drm_context *drm_ctx,int drm_fd, int TexWidth, int TexHeight,int bpp,int *fd,unsigned int *handle,size_t *actual_size);
45 |
46 | int drm_buf_destroy(drm_context *drm_ctx,int drm_fd,int buf_fd, int handle,void *drm_buf,size_t size);
47 |
48 | void drm_deinit(drm_context *drm_ctx, int drm_fd);
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 | #endif /*__DRM_FUNC_H__*/
--------------------------------------------------------------------------------
/rknpu2_ros_common/include/rknpu2_ros_common/model_loader.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | static unsigned char* load_data(FILE* fp, size_t ofst, size_t sz)
10 | {
11 | unsigned char* data;
12 | int ret;
13 |
14 | data = NULL;
15 |
16 | if (NULL == fp) {
17 | return NULL;
18 | }
19 |
20 | ret = fseek(fp, ofst, SEEK_SET);
21 | if (ret != 0) {
22 | printf("blob seek failure.\n");
23 | return NULL;
24 | }
25 |
26 | data = (unsigned char*)malloc(sz);
27 | if (data == NULL) {
28 | printf("buffer malloc failure.\n");
29 | return NULL;
30 | }
31 | ret = fread(data, 1, sz, fp);
32 | return data;
33 | }
34 |
35 | static unsigned char* load_model(const char* filename, int* model_size)
36 | {
37 | FILE* fp;
38 | unsigned char* data;
39 |
40 | fp = fopen(filename, "rb");
41 | if (NULL == fp) {
42 | printf("Open file %s failed.\n", filename);
43 | return NULL;
44 | }
45 |
46 | fseek(fp, 0, SEEK_END);
47 | int size = ftell(fp);
48 |
49 | data = load_data(fp, 0, size);
50 |
51 | fclose(fp);
52 |
53 | *model_size = size;
54 | return data;
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/rknpu2_ros_common/include/rknpu2_ros_common/object.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | namespace rknpu2_ros
6 | {
7 |
8 | struct Object
9 | {
10 | cv::Rect_ rect;
11 | int label;
12 | float prob;
13 | };
14 |
15 | }
--------------------------------------------------------------------------------
/rknpu2_ros_common/include/rknpu2_ros_common/rga_func.h:
--------------------------------------------------------------------------------
1 | #ifndef __RGA_FUNC_H__
2 | #define __RGA_FUNC_H__
3 |
4 | #include
5 | #include "RgaApi.h"
6 |
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 | typedef int(* FUNC_RGA_INIT)();
12 | typedef void(* FUNC_RGA_DEINIT)();
13 | typedef int(* FUNC_RGA_BLIT)(rga_info_t *, rga_info_t *, rga_info_t *);
14 |
15 | typedef struct _rga_context{
16 | void *rga_handle;
17 | FUNC_RGA_INIT init_func;
18 | FUNC_RGA_DEINIT deinit_func;
19 | FUNC_RGA_BLIT blit_func;
20 | } rga_context;
21 |
22 | int RGA_init(rga_context* rga_ctx);
23 |
24 | void img_resize_fast(rga_context *rga_ctx, int src_fd, int src_w, int src_h, uint64_t dst_phys, int dst_w, int dst_h);
25 |
26 | void img_resize_slow(rga_context *rga_ctx, void *src_virt, int src_w, int src_h, void *dst_virt, int dst_w, int dst_h);
27 |
28 | int RGA_deinit(rga_context* rga_ctx);
29 |
30 | #ifdef __cplusplus
31 | }
32 | #endif
33 | #endif/*__RGA_FUNC_H__*/
34 |
--------------------------------------------------------------------------------
/rknpu2_ros_common/include/rknpu2_ros_common/utils.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "object.hpp"
8 | #include "coco_names.hpp"
9 |
10 | #include "bboxes_ex_msgs/msg/bounding_box.hpp"
11 | #include "bboxes_ex_msgs/msg/bounding_boxes.hpp"
12 |
13 | namespace rknpu2_ros
14 | {
15 | namespace utils
16 | {
17 |
18 | static std::vector read_class_labels_file(std::string file_name)
19 | {
20 | std::vector class_names;
21 | std::ifstream ifs(file_name);
22 | std::string buff;
23 | if (ifs.fail())
24 | {
25 | return class_names;
26 | }
27 | while (getline(ifs, buff))
28 | {
29 | if (buff == "")
30 | continue;
31 | class_names.push_back(buff);
32 | }
33 | return class_names;
34 | }
35 |
36 | static void draw_objects(cv::Mat bgr, const std::vector