From 103c053ebb8882780d39e504eb8a5bc927d12446 Mon Sep 17 00:00:00 2001 From: Tuan Nghia Nguyen Date: Wed, 26 Aug 2026 11:27:25 +1000 Subject: [PATCH] ANSFR: emit numeric AgeYears in face attributes; clearer demo overlays - FaceAttributeToJsonString now adds "AgeYears":"" beside the existing "Age" bucket (Kids/Young Adults/Adults/Elders) - additive key, existing consumers parsing "Age" are unaffected. - Classroom demo overlay: explicit per-line labels (Gender: / Age: / Emotion:) and the numeric age in parentheses, e.g. "Age: Adults (28)". Co-Authored-By: Claude Fable 5 --- modules/ANSFR/ANSFRCommon.cpp | 3 +++ tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/ANSFR/ANSFRCommon.cpp b/modules/ANSFR/ANSFRCommon.cpp index ba2cca3..fc95b49 100644 --- a/modules/ANSFR/ANSFRCommon.cpp +++ b/modules/ANSFR/ANSFRCommon.cpp @@ -638,6 +638,9 @@ namespace ANSCENTER { detectedNode.put("Age", "Adults"); else detectedNode.put("Age", "Elders"); + // Numeric age alongside the bucket — additive key, existing + // consumers keep parsing "Age" unchanged. + detectedNode.put("AgeYears", std::to_string(age)); } if (face.isEmotionsEnabled()) { diff --git a/tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp b/tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp index b178654..5d5810f 100644 --- a/tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp +++ b/tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp @@ -1891,7 +1891,7 @@ int ClassroomAttributesVideoTest() // extra_info is itself a JSON string: // {"attributes":[{"Gender":..,"Age":..,"Emotion":..,"Pose(r,p,y)":..}]} - std::string gender, age, emotion; + std::string gender, age, ageYears, emotion; const auto extra = GetData(r, "extra_info"); if (!extra.empty()) { try { @@ -1900,15 +1900,18 @@ int ClassroomAttributesVideoTest() boost::property_tree::read_json(ess, ept); if (ept.count("attributes")) { for (const auto& attr : ept.get_child("attributes")) { - gender = GetOptionalValue(attr.second, "Gender", ""); - age = GetOptionalValue(attr.second, "Age", ""); - emotion = GetOptionalValue(attr.second, "Emotion", ""); + gender = GetOptionalValue(attr.second, "Gender", ""); + age = GetOptionalValue(attr.second, "Age", ""); + ageYears = GetOptionalValue(attr.second, "AgeYears", ""); + emotion = GetOptionalValue(attr.second, "Emotion", ""); break; } } } catch (...) {} } + if (!ageYears.empty()) + age += " (" + ageYears + ")"; const bool known = (name != "Unknown"); const cv::Scalar boxColor = known ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 200, 255); @@ -1916,10 +1919,12 @@ int ClassroomAttributesVideoTest() std::vector lines; lines.push_back(name); - if (!gender.empty() || !age.empty()) - lines.push_back(gender + " / " + age); + if (!gender.empty()) + lines.push_back("Gender: " + gender); + if (!age.empty()) + lines.push_back("Age: " + age); if (!emotion.empty()) - lines.push_back(emotion); + lines.push_back("Emotion: " + emotion); int ty = y - 8 - 18 * static_cast(lines.size() - 1); for (const auto& line : lines) {