Use image processor for yolo input resize

This commit is contained in:
tian 2026-03-14 16:25:18 +08:00
parent c84f2151a3
commit 3b778b70dd
5 changed files with 51 additions and 3 deletions

View File

@ -37,6 +37,9 @@
"type": "ai_yolo",
"role": "filter",
"enable": true,
"use_rga": true,
"rga_gate": "person_shoe_two_stage",
"rga_max_inflight": 4,
"infer_fps": 2,
"model_path": "./models/yolov8n-640.rknn",
"model_version": "v8",

View File

@ -37,6 +37,9 @@
"type": "ai_yolo",
"role": "filter",
"enable": true,
"use_rga": true,
"rga_gate": "person_shoe_two_stage_balanced",
"rga_max_inflight": 4,
"infer_fps": 2,
"model_path": "./models/yolov8n-640.rknn",
"model_version": "v8",

View File

@ -37,6 +37,9 @@
"type": "ai_yolo",
"role": "filter",
"enable": true,
"use_rga": true,
"rga_gate": "person_shoe_two_stage_recall",
"rga_max_inflight": 4,
"infer_fps": 3,
"model_path": "./models/yolov8n-640.rknn",
"model_version": "v8",

View File

@ -10,6 +10,7 @@
#include <thread>
#include <vector>
#include "hw/i_image_processor.h"
#include "hw/i_infer_backend.h"
#include "node.h"
#include "utils/dma_alloc.h"
@ -732,6 +733,7 @@ public:
LogError("[ai_yolo] no infer backend for node " + id_);
return false;
}
image_processor_ = ctx.image_processor;
#if defined(RK3588_ENABLE_RKNN)
if (model_path_.empty()) {
@ -895,7 +897,6 @@ private:
return;
}
if (frame->DmaFd() >= 0) frame->SyncStart();
const size_t input_row = static_cast<size_t>(model_input_w_) * 3;
const size_t input_size = input_row * static_cast<size_t>(model_input_h_);
resized_input_.resize(input_size);
@ -906,12 +907,49 @@ private:
src + static_cast<size_t>(y) * static_cast<size_t>(src_stride),
input_row);
}
} else if (image_processor_ && w > 0 && h > 0) {
Frame src_frame;
src_frame.width = w;
src_frame.height = h;
src_frame.format = PixelFormat::RGB;
src_frame.stride = src_stride;
src_frame.data = const_cast<uint8_t*>(src);
src_frame.data_size = frame->data_size;
src_frame.plane_count = 1;
src_frame.planes[0] = {src_frame.data, src_stride, static_cast<int>(frame->data_size), 0};
Frame resized_frame;
resized_frame.width = model_input_w_;
resized_frame.height = model_input_h_;
resized_frame.format = PixelFormat::RGB;
Status st = image_processor_->Resize(src_frame, resized_frame);
if (st.Ok()) {
const uint8_t* resized_data = resized_frame.planes[0].data ? resized_frame.planes[0].data : resized_frame.data;
const int resized_stride = resized_frame.planes[0].stride > 0
? resized_frame.planes[0].stride
: (resized_frame.stride > 0 ? resized_frame.stride : static_cast<int>(input_row));
if (resized_data && resized_stride > 0) {
for (int y = 0; y < model_input_h_; ++y) {
memcpy(resized_input_.data() + static_cast<size_t>(y) * input_row,
resized_data + static_cast<size_t>(y) * static_cast<size_t>(resized_stride),
input_row);
}
} else {
ResizeRgbBilinear(src, w, h, src_stride,
resized_input_.data(), model_input_w_, model_input_h_,
static_cast<int>(input_row));
}
} else {
ResizeRgbBilinear(src, w, h, src_stride,
resized_input_.data(), model_input_w_, model_input_h_,
static_cast<int>(input_row));
}
} else {
ResizeRgbBilinear(src, w, h, src_stride,
resized_input_.data(), model_input_w_, model_input_h_,
static_cast<int>(input_row));
}
if (frame->DmaFd() >= 0) frame->SyncEnd();
input.data = resized_input_.data();
input.size = input_size;
input.width = model_input_w_;
@ -1252,6 +1290,7 @@ private:
std::shared_ptr<SpscQueue<FramePtr>> input_queue_;
std::vector<std::shared_ptr<SpscQueue<FramePtr>>> output_queues_;
std::shared_ptr<IImageProcessor> image_processor_;
std::shared_ptr<IInferBackend> infer_backend_;
uint64_t processed_ = 0;

View File

@ -495,7 +495,7 @@ bool Graph::Build(const SimpleJson& graph_cfg, PluginLoader& loader, size_t defa
entry.enabled = node_val.ValueOr<bool>("enable", true);
entry.metrics = std::make_shared<NodeMetrics>();
entry.context.infer_backend = infer_backend_;
if (entry.type == "preprocess" || entry.type == "ai_shoe_det") {
if (entry.type == "preprocess" || entry.type == "ai_shoe_det" || entry.type == "ai_yolo") {
entry.context.image_processor = HwFactory::CreateImageProcessor(entry.config);
}