o4.6做了修改
This commit is contained in:
parent
aaa794fe10
commit
631f2a1f4a
@ -35,7 +35,7 @@
|
||||
"dst_h": 768,
|
||||
"dst_format": "rgb",
|
||||
"dst_packed": true,
|
||||
"resize_mode": "letterbox",
|
||||
"resize_mode": "stretch",
|
||||
"keep_ratio": false,
|
||||
"rga_gate": "cam_ppe11_yolo_debug",
|
||||
"use_rga": true
|
||||
|
||||
@ -951,11 +951,11 @@ private:
|
||||
NMS(valid_count, boxes, class_ids, indices, c, nms_thresh_);
|
||||
}
|
||||
|
||||
const DetCoordContext coord_ctx = BuildDetCoordContext(*frame, model_input_w_, model_input_h_);
|
||||
|
||||
auto det_result = std::make_shared<DetectionResult>();
|
||||
det_result->img_w = coord_ctx.out_w;
|
||||
det_result->img_h = coord_ctx.out_h;
|
||||
// README 约定: img_w/img_h = 推理输入宽/高(当前帧空间)
|
||||
// 坐标缩放由下游 preprocess 的 ScaleMeta 负责
|
||||
det_result->img_w = frame->width;
|
||||
det_result->img_h = frame->height;
|
||||
det_result->model_name = (yolo_version_ == YoloVersion::V5) ? "yolov5" : "yolov8";
|
||||
|
||||
for (int i = 0; i < valid_count && det_result->items.size() < kMaxDetections; ++i) {
|
||||
@ -975,7 +975,10 @@ private:
|
||||
Detection det;
|
||||
det.cls_id = cls_id;
|
||||
det.score = obj_probs[i];
|
||||
det.bbox = DecodeToOutputRect(x1, y1, w, h, coord_ctx);
|
||||
det.bbox.x = std::max(0.0f, std::min(x1, static_cast<float>(frame->width)));
|
||||
det.bbox.y = std::max(0.0f, std::min(y1, static_cast<float>(frame->height)));
|
||||
det.bbox.w = std::max(0.0f, std::min(w, static_cast<float>(frame->width) - det.bbox.x));
|
||||
det.bbox.h = std::max(0.0f, std::min(h, static_cast<float>(frame->height) - det.bbox.y));
|
||||
det.track_id = -1;
|
||||
|
||||
if (debug_det_ && det_result->items.size() < 5 && processed_ < 20) {
|
||||
@ -1101,11 +1104,9 @@ private:
|
||||
NMS(valid_count, boxes, class_ids, indices, c, nms_thresh_);
|
||||
}
|
||||
|
||||
const DetCoordContext coord_ctx = BuildDetCoordContext(*frame, model_input_w_, model_input_h_);
|
||||
|
||||
auto det_result = std::make_shared<DetectionResult>();
|
||||
det_result->img_w = coord_ctx.out_w;
|
||||
det_result->img_h = coord_ctx.out_h;
|
||||
det_result->img_w = frame->width;
|
||||
det_result->img_h = frame->height;
|
||||
det_result->model_name = (yolo_version_ == YoloVersion::V5) ? "yolov5" : "yolov8";
|
||||
|
||||
for (int i = 0; i < valid_count && det_result->items.size() < kMaxDetections; ++i) {
|
||||
@ -1125,7 +1126,10 @@ private:
|
||||
Detection det;
|
||||
det.cls_id = cls_id;
|
||||
det.score = obj_probs[i];
|
||||
det.bbox = DecodeToOutputRect(x1, y1, w, h, coord_ctx);
|
||||
det.bbox.x = std::max(0.0f, std::min(x1, static_cast<float>(frame->width)));
|
||||
det.bbox.y = std::max(0.0f, std::min(y1, static_cast<float>(frame->height)));
|
||||
det.bbox.w = std::max(0.0f, std::min(w, static_cast<float>(frame->width) - det.bbox.x));
|
||||
det.bbox.h = std::max(0.0f, std::min(h, static_cast<float>(frame->height) - det.bbox.y));
|
||||
det.track_id = -1;
|
||||
|
||||
if (debug_det_ && det_result->items.size() < 5 && processed_ < 20) {
|
||||
|
||||
@ -77,6 +77,21 @@ Rect MapRectToFrame(const Rect& in, int src_w, int src_h, int dst_w, int dst_h)
|
||||
return out;
|
||||
}
|
||||
|
||||
// 利用 transform_meta 将原图空间坐标正确映射回当前帧空间
|
||||
// 正向变换: frame_x = orig_x * scale_x + pad_x
|
||||
Rect MapRectWithTransform(const Rect& in, const FrameTransformMeta& tx, int frame_w, int frame_h) {
|
||||
const float fw = static_cast<float>(frame_w);
|
||||
const float fh = static_cast<float>(frame_h);
|
||||
Rect out{};
|
||||
out.x = std::max(0.0f, in.x * tx.scale_x + tx.pad_x);
|
||||
out.y = std::max(0.0f, in.y * tx.scale_y + tx.pad_y);
|
||||
out.w = std::max(0.0f, in.w * tx.scale_x);
|
||||
out.h = std::max(0.0f, in.h * tx.scale_y);
|
||||
if (out.x + out.w > fw) out.w = std::max(0.0f, fw - out.x);
|
||||
if (out.y + out.h > fh) out.h = std::max(0.0f, fh - out.y);
|
||||
return out;
|
||||
}
|
||||
|
||||
#if defined(RK3588_ENABLE_RGA)
|
||||
inline uint32_t PackColorArgb(const Color& c) {
|
||||
return (0xFFu << 24) | (static_cast<uint32_t>(c.r) << 16) |
|
||||
@ -578,6 +593,11 @@ private:
|
||||
const int det_w = frame->det->img_w > 0 ? frame->det->img_w : w;
|
||||
const int det_h = frame->det->img_h > 0 ? frame->det->img_h : h;
|
||||
const bool map_det_to_frame = (det_w != w || det_h != h);
|
||||
// 优先使用 transform_meta 做 letterbox 感知的坐标映射
|
||||
const bool use_transform = map_det_to_frame && frame->transform_meta &&
|
||||
frame->transform_meta->valid &&
|
||||
frame->transform_meta->scale_x > 1e-6f &&
|
||||
frame->transform_meta->scale_y > 1e-6f;
|
||||
uint8_t* data = frame->planes[0].data ? frame->planes[0].data : frame->data;
|
||||
PixelFormat fmt = frame->format;
|
||||
|
||||
@ -604,7 +624,8 @@ private:
|
||||
} else {
|
||||
bool ok = true;
|
||||
for (const auto& det : frame->det->items) {
|
||||
const Rect draw = map_det_to_frame ? MapRectToFrame(det.bbox, det_w, det_h, w, h) : det.bbox;
|
||||
const Rect draw = use_transform ? MapRectWithTransform(det.bbox, *frame->transform_meta, w, h)
|
||||
: (map_det_to_frame ? MapRectToFrame(det.bbox, det_w, det_h, w, h) : det.bbox);
|
||||
int x = Clamp(static_cast<int>(draw.x), 0, w - 1);
|
||||
int y = Clamp(static_cast<int>(draw.y), 0, h - 1);
|
||||
int rw = static_cast<int>(draw.w);
|
||||
@ -654,7 +675,8 @@ private:
|
||||
}
|
||||
|
||||
for (const auto& det : frame->det->items) {
|
||||
const Rect draw = map_det_to_frame ? MapRectToFrame(det.bbox, det_w, det_h, w, h) : det.bbox;
|
||||
const Rect draw = use_transform ? MapRectWithTransform(det.bbox, *frame->transform_meta, w, h)
|
||||
: (map_det_to_frame ? MapRectToFrame(det.bbox, det_w, det_h, w, h) : det.bbox);
|
||||
int x1 = static_cast<int>(draw.x);
|
||||
int y1 = static_cast<int>(draw.y);
|
||||
int x2 = static_cast<int>(draw.x + draw.w);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user