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;