测试人脸识别功能,刚刚开发完成,画人脸识别框
Some checks are pending
CI / host-build (push) Waiting to run
CI / rk3588-cross-build (push) Waiting to run

This commit is contained in:
sladro 2026-01-07 17:27:25 +08:00
parent 7f30d70d5a
commit 32b642cb39
2 changed files with 46 additions and 1 deletions

View File

@ -49,6 +49,7 @@
"enable": true,
"draw_bbox": true,
"draw_text": true,
"draw_face_det": true,
"line_width": 2,
"font_scale": 1,
"labels": []

View File

@ -287,6 +287,7 @@ public:
id_ = config.ValueOr<std::string>("id", "osd");
draw_bbox_ = config.ValueOr<bool>("draw_bbox", true);
draw_text_ = config.ValueOr<bool>("draw_text", true);
draw_face_det_ = config.ValueOr<bool>("draw_face_det", false);
line_width_ = config.ValueOr<int>("line_width", 2);
font_scale_ = config.ValueOr<int>("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<int>(it.bbox.x);
int y1 = static_cast<int>(it.bbox.y);
int x2 = static_cast<int>(it.bbox.x + it.bbox.w);
int y2 = static_cast<int>(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<std::string> labels_;