Use image processor for shoe ROI resize
This commit is contained in:
parent
d475cb890f
commit
324bd3296c
@ -74,6 +74,9 @@
|
||||
"type": "ai_shoe_det",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"use_rga": true,
|
||||
"rga_gate": "person_shoe_two_stage",
|
||||
"rga_max_inflight": 4,
|
||||
"infer_fps": 1,
|
||||
"model_path": "./models/shoe_detector_openimages_ppe_v1.rknn",
|
||||
"model_w": 640,
|
||||
|
||||
@ -74,6 +74,9 @@
|
||||
"type": "ai_shoe_det",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"use_rga": true,
|
||||
"rga_gate": "person_shoe_two_stage_balanced",
|
||||
"rga_max_inflight": 4,
|
||||
"infer_fps": 1,
|
||||
"model_path": "./models/shoe_detector_openimages_ppe_v1.rknn",
|
||||
"model_w": 640,
|
||||
|
||||
@ -74,6 +74,9 @@
|
||||
"type": "ai_shoe_det",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"use_rga": true,
|
||||
"rga_gate": "person_shoe_two_stage_recall",
|
||||
"rga_max_inflight": 4,
|
||||
"infer_fps": 2,
|
||||
"model_path": "./models/shoe_detector_openimages_ppe_v1.rknn",
|
||||
"model_w": 640,
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
#include "ai_scheduler.h"
|
||||
#include "frame/frame.h"
|
||||
#include "hw/i_image_processor.h"
|
||||
#include "hw/i_infer_backend.h"
|
||||
#include "node.h"
|
||||
#include "utils/logger.h"
|
||||
@ -365,6 +366,7 @@ public:
|
||||
LogError("[ai_shoe_det] no infer backend");
|
||||
return false;
|
||||
}
|
||||
image_processor_ = ctx.image_processor;
|
||||
|
||||
#if defined(RK3588_ENABLE_RKNN)
|
||||
std::string err;
|
||||
@ -562,17 +564,61 @@ private:
|
||||
memcpy(dst_row, src_row, static_cast<size_t>(win_w) * 3);
|
||||
}
|
||||
|
||||
// Resize 到模型输入尺寸
|
||||
ResizeRgbBilinear(crop_buf.data(), win_w, win_h, win_w * 3,
|
||||
input_buf_.data(), model_w_, model_h_, model_w_ * 3);
|
||||
const uint8_t* model_input_data = nullptr;
|
||||
size_t model_input_size = 0;
|
||||
|
||||
if (image_processor_ && win_w > 0 && win_h > 0) {
|
||||
Frame crop_frame;
|
||||
crop_frame.width = win_w;
|
||||
crop_frame.height = win_h;
|
||||
crop_frame.format = PixelFormat::RGB;
|
||||
crop_frame.stride = win_w * 3;
|
||||
crop_frame.data = crop_buf.data();
|
||||
crop_frame.data_size = crop_buf.size();
|
||||
crop_frame.plane_count = 1;
|
||||
crop_frame.planes[0] = {crop_buf.data(), crop_frame.stride, static_cast<int>(crop_buf.size()), 0};
|
||||
|
||||
Frame resized_frame;
|
||||
resized_frame.width = model_w_;
|
||||
resized_frame.height = model_h_;
|
||||
resized_frame.format = PixelFormat::RGB;
|
||||
|
||||
Status st = image_processor_->Resize(crop_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 : model_w_ * 3);
|
||||
const size_t packed_size = static_cast<size_t>(model_w_) * static_cast<size_t>(model_h_) * 3;
|
||||
if (resized_data && resized_stride > 0) {
|
||||
if (packed_size > input_buf_.size()) input_buf_.resize(packed_size);
|
||||
if (resized_frame.DmaFd() >= 0) resized_frame.SyncStart();
|
||||
for (int row = 0; row < model_h_; ++row) {
|
||||
memcpy(input_buf_.data() + static_cast<size_t>(row) * static_cast<size_t>(model_w_) * 3,
|
||||
resized_data + static_cast<size_t>(row) * static_cast<size_t>(resized_stride),
|
||||
static_cast<size_t>(model_w_) * 3);
|
||||
}
|
||||
if (resized_frame.DmaFd() >= 0) resized_frame.SyncEnd();
|
||||
model_input_data = input_buf_.data();
|
||||
model_input_size = packed_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!model_input_data) {
|
||||
ResizeRgbBilinear(crop_buf.data(), win_w, win_h, win_w * 3,
|
||||
input_buf_.data(), model_w_, model_h_, model_w_ * 3);
|
||||
model_input_data = input_buf_.data();
|
||||
model_input_size = input_buf_.size();
|
||||
}
|
||||
|
||||
// 推理
|
||||
InferInput input;
|
||||
input.width = model_w_;
|
||||
input.height = model_h_;
|
||||
input.is_nhwc = true;
|
||||
input.data = input_buf_.data();
|
||||
input.size = input_buf_.size();
|
||||
input.data = model_input_data;
|
||||
input.size = model_input_size;
|
||||
input.type = RKNN_TENSOR_UINT8;
|
||||
|
||||
auto r = infer_backend_->InferBorrowed(model_handle_, input);
|
||||
@ -766,6 +812,7 @@ private:
|
||||
|
||||
std::shared_ptr<SpscQueue<FramePtr>> input_queue_;
|
||||
std::vector<std::shared_ptr<SpscQueue<FramePtr>>> output_queues_;
|
||||
std::shared_ptr<IImageProcessor> image_processor_;
|
||||
|
||||
#if defined(RK3588_ENABLE_RKNN)
|
||||
std::shared_ptr<IInferBackend> infer_backend_;
|
||||
|
||||
@ -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") {
|
||||
if (entry.type == "preprocess" || entry.type == "ai_shoe_det") {
|
||||
entry.context.image_processor = HwFactory::CreateImageProcessor(entry.config);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user