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_;