From 7b0171f48a43e0cafe51e6c32cdcdd07f35af013 Mon Sep 17 00:00:00 2001 From: sladro Date: Wed, 7 Jan 2026 18:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=BA=E8=84=B8=E7=94=BB?= =?UTF-8?q?=E6=A1=86,xin2,=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=94=BB=E6=A1=86?= =?UTF-8?q?=E4=BA=BA=E8=84=B8=E8=AF=86=E5=88=AB=E7=BB=93=E6=9E=9C=EF=BC=8C?= =?UTF-8?q?=E5=90=8E=E9=9D=A2=E8=A6=81=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/osd/osd_node.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/plugins/osd/osd_node.cpp b/plugins/osd/osd_node.cpp index 824ae6f..14a7cf2 100644 --- a/plugins/osd/osd_node.cpp +++ b/plugins/osd/osd_node.cpp @@ -331,11 +331,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,6 +478,43 @@ private: } } + void DrawFaceDet(FramePtr frame) { + 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}; + 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;