bonus-edge-proxy/src/rknn_test/rkYolov8.hpp

59 lines
1.3 KiB
C++
Raw Normal View History

2026-01-19 13:06:51 +08:00
#ifndef RKYOLOV8_HPP
#define RKYOLOV8_HPP
2026-01-16 16:44:50 +08:00
2026-01-19 13:06:51 +08:00
#include <memory>
#include <opencv2/opencv.hpp>
2026-01-16 16:44:50 +08:00
#include <string>
#include <vector>
#include "rknn/rknn_api.h"
#include "rknn_test/postprocess.h"
2026-01-19 13:06:51 +08:00
// 引入我们刚才修复的 DMA 分配器
#include "rknn_test/dma_allocator.hpp"
2026-01-16 16:44:50 +08:00
namespace rknn_test {
class rkYolov8 {
2026-01-19 13:06:51 +08:00
public:
rkYolov8(const std::string& model_path, const std::string& label_path, int class_num);
~rkYolov8();
2026-01-16 16:44:50 +08:00
2026-01-19 13:06:51 +08:00
int init(rknn_context* ctx_in, bool is_slave);
rknn_context* get_pctx();
detect_result_group_t infer(const cv::Mat& ori_img);
2026-01-16 16:44:50 +08:00
2026-01-19 13:06:51 +08:00
private:
unsigned char* load_model(const char* filename, int* model_size);
void post_process_v8_dfl(rknn_output* outputs, float scale, int pad_w, int pad_h,
detect_result_group_t* group);
2026-01-16 16:44:50 +08:00
2026-01-19 13:06:51 +08:00
private:
std::string model_path;
2026-01-16 16:44:50 +08:00
std::string m_label_path;
int m_class_num;
2026-01-19 13:06:51 +08:00
rknn_context ctx;
bool is_slave = false;
unsigned char* model_data = nullptr;
2026-01-16 16:44:50 +08:00
2026-01-19 13:06:51 +08:00
rknn_input_output_num io_num;
rknn_tensor_attr* input_attrs = nullptr;
rknn_tensor_attr* output_attrs = nullptr;
2026-01-16 16:44:50 +08:00
2026-01-19 13:06:51 +08:00
rknn_input inputs[1];
2026-01-16 16:44:50 +08:00
2026-01-19 13:06:51 +08:00
int width = 0;
int height = 0;
int channel = 0;
2026-01-16 16:44:50 +08:00
2026-01-19 13:06:51 +08:00
float conf_threshold;
float nms_threshold;
// 【修改点】使用 DmaBuffer 智能指针管理 NPU 输入内存
std::unique_ptr<DmaBuffer> input_dma_buf_;
2026-01-16 16:44:50 +08:00
};
2026-01-19 13:06:51 +08:00
2026-01-16 16:44:50 +08:00
} // namespace rknn_test
2026-01-19 13:06:51 +08:00
#endif // RKYOLOV8_HPP