Keep high-res frames for two-stage shoe ROI
This commit is contained in:
parent
56997d019c
commit
cdc3c46932
@ -24,8 +24,8 @@
|
||||
"type": "preprocess",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"dst_w": 640,
|
||||
"dst_h": 640,
|
||||
"dst_w": 1920,
|
||||
"dst_h": 1080,
|
||||
"dst_format": "rgb",
|
||||
"dst_packed": true,
|
||||
"resize_mode": "stretch",
|
||||
|
||||
@ -817,6 +817,38 @@ private:
|
||||
}
|
||||
|
||||
#if defined(RK3588_ENABLE_RKNN)
|
||||
void ResizeRgbBilinear(const uint8_t* src, int src_w, int src_h, int src_stride,
|
||||
uint8_t* dst, int dst_w, int dst_h, int dst_stride) {
|
||||
const float scale_x = static_cast<float>(src_w) / static_cast<float>(dst_w);
|
||||
const float scale_y = static_cast<float>(src_h) / static_cast<float>(dst_h);
|
||||
|
||||
for (int y = 0; y < dst_h; ++y) {
|
||||
const float fy = static_cast<float>(y) * scale_y;
|
||||
const int y0 = static_cast<int>(fy);
|
||||
const int y1 = std::min(y0 + 1, src_h - 1);
|
||||
const float dy = fy - static_cast<float>(y0);
|
||||
|
||||
for (int x = 0; x < dst_w; ++x) {
|
||||
const float fx = static_cast<float>(x) * scale_x;
|
||||
const int x0 = static_cast<int>(fx);
|
||||
const int x1 = std::min(x0 + 1, src_w - 1);
|
||||
const float dx = fx - static_cast<float>(x0);
|
||||
|
||||
for (int c = 0; c < 3; ++c) {
|
||||
const float v00 = src[y0 * src_stride + x0 * 3 + c];
|
||||
const float v01 = src[y0 * src_stride + x1 * 3 + c];
|
||||
const float v10 = src[y1 * src_stride + x0 * 3 + c];
|
||||
const float v11 = src[y1 * src_stride + x1 * 3 + c];
|
||||
const float v = v00 * (1.0f - dx) * (1.0f - dy) +
|
||||
v01 * dx * (1.0f - dy) +
|
||||
v10 * (1.0f - dx) * dy +
|
||||
v11 * dx * dy;
|
||||
dst[y * dst_stride + x * 3 + c] = static_cast<uint8_t>(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RunInference(FramePtr frame) {
|
||||
if (!frame->data || frame->data_size == 0) return;
|
||||
|
||||
@ -837,9 +869,12 @@ private:
|
||||
if (!src || src_stride <= 0) return;
|
||||
|
||||
InferInput input;
|
||||
if (static_cast<size_t>(src_stride) == packed_row && frame->data_size >= packed_size) {
|
||||
const bool exact_model_input = (w == model_input_w_ && h == model_input_h_);
|
||||
if (exact_model_input && static_cast<size_t>(src_stride) == packed_row && frame->data_size >= packed_size) {
|
||||
input.data = src;
|
||||
input.size = packed_size;
|
||||
input.width = w;
|
||||
input.height = h;
|
||||
|
||||
// Best-effort RKNN DMA-BUF zero-copy path.
|
||||
if (frame->DmaFd() >= 0 && frame->data) {
|
||||
@ -858,18 +893,27 @@ private:
|
||||
}
|
||||
|
||||
if (frame->DmaFd() >= 0) frame->SyncStart();
|
||||
rgb_tmp_.resize(packed_size);
|
||||
for (int y = 0; y < h; ++y) {
|
||||
memcpy(rgb_tmp_.data() + static_cast<size_t>(y) * packed_row,
|
||||
src + static_cast<size_t>(y) * static_cast<size_t>(src_stride),
|
||||
packed_row);
|
||||
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);
|
||||
|
||||
if (exact_model_input) {
|
||||
for (int y = 0; y < h; ++y) {
|
||||
memcpy(resized_input_.data() + static_cast<size_t>(y) * input_row,
|
||||
src + static_cast<size_t>(y) * static_cast<size_t>(src_stride),
|
||||
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 = rgb_tmp_.data();
|
||||
input.size = packed_size;
|
||||
input.data = resized_input_.data();
|
||||
input.size = input_size;
|
||||
input.width = model_input_w_;
|
||||
input.height = model_input_h_;
|
||||
}
|
||||
input.width = w;
|
||||
input.height = h;
|
||||
input.is_nhwc = true;
|
||||
|
||||
auto result = infer_backend_->InferBorrowed(model_handle_, input);
|
||||
@ -1219,7 +1263,7 @@ private:
|
||||
#if defined(RK3588_ENABLE_RKNN)
|
||||
ModelHandle model_handle_ = kInvalidModelHandle;
|
||||
uint32_t n_output_ = 0;
|
||||
std::vector<uint8_t> rgb_tmp_;
|
||||
std::vector<uint8_t> resized_input_;
|
||||
std::vector<float> fp32_buffer_; // For FP16 to FP32 conversion
|
||||
#endif
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user