From 32b642cb3988f8def8ca6e8a9f20bf151930f230 Mon Sep 17 00:00:00 2001 From: sladro Date: Wed, 7 Jan 2026 17:27:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BA=BA=E8=84=B8=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=88=9A=E5=88=9A=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E5=AE=8C=E6=88=90=EF=BC=8C=E7=94=BB=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/test_cam1_face_det_rtsp_server.json | 1 + plugins/osd/osd_node.cpp | 46 ++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/configs/test_cam1_face_det_rtsp_server.json b/configs/test_cam1_face_det_rtsp_server.json index 2c9716f..0f3c23b 100644 --- a/configs/test_cam1_face_det_rtsp_server.json +++ b/configs/test_cam1_face_det_rtsp_server.json @@ -49,6 +49,7 @@ "enable": true, "draw_bbox": true, "draw_text": true, + "draw_face_det": true, "line_width": 2, "font_scale": 1, "labels": [] diff --git a/plugins/osd/osd_node.cpp b/plugins/osd/osd_node.cpp index 824ae6f..60543e8 100644 --- a/plugins/osd/osd_node.cpp +++ b/plugins/osd/osd_node.cpp @@ -287,6 +287,7 @@ public: id_ = config.ValueOr("id", "osd"); draw_bbox_ = config.ValueOr("draw_bbox", true); draw_text_ = config.ValueOr("draw_text", true); + draw_face_det_ = config.ValueOr("draw_face_det", false); line_width_ = config.ValueOr("line_width", 2); font_scale_ = config.ValueOr("font_scale", 1); @@ -331,11 +332,12 @@ public: if (!frame) return NodeStatus::DROP; FramePtr out = frame; - if (out->data && (out->det || out->face_recog)) { + if (out->data && (out->det || out->face_det || out->face_recog)) { if (out.use_count() > 1) { out = CloneFrameForWrite(out); } DrawDetections(out); + DrawFaceDet(out); DrawFaceRecog(out); } @@ -477,9 +479,51 @@ private: } } + void DrawFaceDet(FramePtr frame) { + if (!draw_face_det_) return; + if (!frame->face_det || frame->face_det->faces.empty()) return; + + int w = frame->width; + int h = frame->height; + uint8_t* data = frame->planes[0].data ? frame->planes[0].data : frame->data; + PixelFormat fmt = frame->format; + + int stride; + if (fmt == PixelFormat::RGB || fmt == PixelFormat::BGR) { + stride = frame->planes[0].stride > 0 ? frame->planes[0].stride + : (frame->stride > 0 ? frame->stride : w * 3); + } else if (fmt == PixelFormat::NV12 || fmt == PixelFormat::YUV420) { + stride = frame->planes[0].stride > 0 ? frame->planes[0].stride + : (frame->stride > 0 ? frame->stride : w); + } else { + return; + } + + const Color color{0, 255, 255}; // face det: cyan + for (const auto& it : frame->face_det->faces) { + int x1 = static_cast(it.bbox.x); + int y1 = static_cast(it.bbox.y); + int x2 = static_cast(it.bbox.x + it.bbox.w); + int y2 = static_cast(it.bbox.y + it.bbox.h); + + if (draw_bbox_) { + DrawRect(data, w, h, stride, fmt, x1, y1, x2, y2, line_width_, color); + } + + if (draw_text_) { + char label[64]; + snprintf(label, sizeof(label), "face %.0f%%", it.score * 100); + int text_y = y1 - 8 * font_scale_; + if (text_y < 0) text_y = y1 + 2; + DrawText(data, w, h, stride, fmt, x1, text_y, label, font_scale_, color); + } + } + } + std::string id_; bool draw_bbox_ = true; bool draw_text_ = true; + bool draw_face_det_ = false; int line_width_ = 2; int font_scale_ = 1; std::vector labels_;