From 8ec2452dcd8ae5d26a8795e9b90223f28c6d0af3 Mon Sep 17 00:00:00 2001 From: EVA x10 Development Date: Wed, 25 Nov 2026 11:41:16 +0100 Subject: [PATCH] Focus distant face detection on the tracked person --- AndroidManifest.xml | 2 +- README.md | 8 ++++---- build.sh | 4 ++-- src/MainActivity.java | 22 +++++++++++++++++++++- src/VisionModels.java | 23 ++++++++++++++--------- tests/PersonTrackerTest.java | 18 +++++++++++++++++- 6 files changed, 59 insertions(+), 18 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 757df1e..2ce2ff0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.it_screen.edgevision" android:versionCode="24" android:versionName="0.3.19"> diff --git a/README.md b/README.md index 7a68f4a..41b1da6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# EVAx10 Video analitics v0.3.18 +# EVAx10 Video analitics v0.3.19 A separate native Android experiment for consenting adult volunteers. Package `com.it_screen.edgevision`. The existing FaceAPI baseline is @@ -10,10 +10,10 @@ installable as `com.it_screen.audiencepoc`. `./build.sh` builds the ARM64, API 30+ APK with the Windows Android SDK 35 and JDK 17 via WSL. The script pins and verifies the upstream Maven AAR. Model assets load locally and are verified before ONNX Runtime session -creation. The signed test build is `build/EVAx10-Video-analitics-0.3.18.apk`. +creation. The signed test build is `build/EVAx10-Video-analitics-0.3.19.apk`. ```text -adb install --no-incremental -r EVAx10-Video-analitics-0.3.18.apk +adb install --no-incremental -r EVAx10-Video-analitics-0.3.19.apk adb shell am start -W -n com.it_screen.edgevision/.MainActivity adb logcat -s EdgeVision EdgeVisionBench ``` @@ -96,7 +96,7 @@ or an Android low-memory signal is red. ### Controlled Face Re-ID PoC Build with `./build.sh --face-reid-poc`. Install -`build/EVAx10-Video-analitics-0.3.18-Face-ReID-PoC.apk` as the separate package +`build/EVAx10-Video-analitics-0.3.19-Face-ReID-PoC.apk` as the separate package `com.it_screen.edgevision.facereidpoc`. Start requires on-device confirmation that all adult test participants consent. Keep other people out of the camera view. The default build excludes the SFace weights and implementation. diff --git a/build.sh b/build.sh index d08b704..b5f8181 100755 --- a/build.sh +++ b/build.sh @@ -20,14 +20,14 @@ if [[ ! -f build/ort.aar ]]; then fi python3 tools/check-production-assets.py manifest=AndroidManifest.xml -apk=build/EVAx10-Video-analitics-0.3.18.apk +apk=build/EVAx10-Video-analitics-0.3.19.apk if [[ $variant == poc ]]; then python3 tools/check-poc-assets.py manifest=build/AndroidManifest-face-reid-poc.xml sed -e 's/package="com.it_screen.edgevision"/package="com.it_screen.edgevision.facereidpoc"/' \ -e 's/android:name=".MainActivity"/android:name="com.it_screen.edgevision.MainActivity"/' \ AndroidManifest.xml > "$manifest" - apk=build/EVAx10-Video-analitics-0.3.18-Face-ReID-PoC.apk + apk=build/EVAx10-Video-analitics-0.3.19-Face-ReID-PoC.apk fi rm -rf build/classes build/dex mkdir -p build/classes build/dex diff --git a/src/MainActivity.java b/src/MainActivity.java index d84832a..160545f 100644 --- a/src/MainActivity.java +++ b/src/MainActivity.java @@ -664,7 +664,9 @@ public final class MainActivity extends Activity { if (now >= nextFaceFrame && tracker.count(PersonTracker.State.ACTIVE) > 0) { nextFaceFrame = now + config.interval; long faceAt = System.nanoTime(); - List faces = detector.detect(frame, config.detection); + Rect faceRegion = faceSearchRegion(frame); + List faces = faceRegion == null ? detector.detect(frame, config.detection) : + detector.detect(frame, config.detection, faceRegion); faceMs = ms(faceAt); faceCount = faces.size(); long ageAt = System.nanoTime(); @@ -769,6 +771,24 @@ public final class MainActivity extends Activity { }); } + private Rect faceSearchRegion(Bitmap frame) { + if (tracker.count(PersonTracker.State.ACTIVE) != 1) return null; + for (PersonTracker.Track track : tracker.tracks()) { + if (track.state != PersonTracker.State.ACTIVE) continue; + PersonTracker.Box body = track.observed; + if (body.height() >= .65f) return null; + // Keep the head and shoulders, with padding for imprecise body boxes. + int width = frame.getWidth(), height = frame.getHeight(); + Rect region = new Rect( + Math.max(0, (int) Math.floor((body.left - .45f * body.width()) * width)), + Math.max(0, (int) Math.floor((body.top - .15f * body.height()) * height)), + Math.min(width, (int) Math.ceil((body.right + .45f * body.width()) * width)), + Math.min(height, (int) Math.ceil((body.top + .65f * body.height()) * height))); + return region.width() >= 24 && region.height() >= 24 ? region : null; + } + return null; + } + private Map associateFaces(List faces) { Map result = new LinkedHashMap<>(); for (Face face : faces) { diff --git a/src/VisionModels.java b/src/VisionModels.java index 2713ae8..da31462 100644 --- a/src/VisionModels.java +++ b/src/VisionModels.java @@ -114,10 +114,14 @@ final class YuNet extends ImageModel implements FaceDetector { YuNet(InferenceEngine.Model session, ModelRegistry.Entry entry) throws Exception { super(session, entry); } @Override public List detect(Bitmap frame, float threshold) throws Exception { - float scale = Math.min((float) width / frame.getWidth(), (float) height / frame.getHeight()); - float drawnWidth = frame.getWidth() * scale; - float drawnHeight = frame.getHeight() * scale; - Map result = run(frame, null, new RectF(0, 0, drawnWidth, drawnHeight)); + return detect(frame, threshold, new Rect(0, 0, frame.getWidth(), frame.getHeight())); + } + + List detect(Bitmap frame, float threshold, Rect crop) throws Exception { + float scale = Math.min((float) width / crop.width(), (float) height / crop.height()); + float drawnWidth = crop.width() * scale; + float drawnHeight = crop.height() * scale; + Map result = run(frame, crop, new RectF(0, 0, drawnWidth, drawnHeight)); List candidates = new ArrayList<>(); for (int stride : new int[]{8,16,32}) { float[] cls = result.get("cls_" + stride); @@ -133,16 +137,17 @@ final class YuNet extends ImageModel implements FaceDetector { float cy = (i / cols + bbox[p + 1]) * stride; float halfW = (float) Math.exp(bbox[p + 2]) * stride / 2; float halfH = (float) Math.exp(bbox[p + 3]) * stride / 2; - RectF rect = new RectF(clamp(cx - halfW, drawnWidth) / drawnWidth, - clamp(cy - halfH, drawnHeight) / drawnHeight, - clamp(cx + halfW, drawnWidth) / drawnWidth, clamp(cy + halfH, drawnHeight) / drawnHeight); + RectF rect = new RectF((crop.left + clamp(cx - halfW, drawnWidth) / scale) / frame.getWidth(), + (crop.top + clamp(cy - halfH, drawnHeight) / scale) / frame.getHeight(), + (crop.left + clamp(cx + halfW, drawnWidth) / scale) / frame.getWidth(), + (crop.top + clamp(cy + halfH, drawnHeight) / scale) / frame.getHeight()); if (rect.width() <= 0 || rect.height() <= 0) continue; float[] landmarks = null; if (points != null) { landmarks = new float[10]; for (int j = 0; j < 5; j++) { - landmarks[2*j] = (i % cols + points[10*i + 2*j]) * stride / scale; - landmarks[2*j+1] = (i / cols + points[10*i + 2*j+1]) * stride / scale; + landmarks[2*j] = crop.left + (i % cols + points[10*i + 2*j]) * stride / scale; + landmarks[2*j+1] = crop.top + (i / cols + points[10*i + 2*j+1]) * stride / scale; } } candidates.add(new Face(rect, score, landmarks)); diff --git a/tests/PersonTrackerTest.java b/tests/PersonTrackerTest.java index 3feae30..358fda3 100644 --- a/tests/PersonTrackerTest.java +++ b/tests/PersonTrackerTest.java @@ -9,6 +9,7 @@ import java.util.List; public final class PersonTrackerTest { private static final long STEP = 200; private static final class Scenario { + long step = STEP; final PersonTracker tracker = new PersonTracker(); final AudienceAggregator totals = new AudienceAggregator(); final Map lastIds = new HashMap<>(); @@ -31,7 +32,7 @@ public final class PersonTrackerTest { Integer previous = lastIds.put(person.truth, assigned.id); if (previous != null && previous != assigned.id) switches++; } - time += STEP; + time += step; } void repeat(int count, Labelled... people) { @@ -51,6 +52,11 @@ public final class PersonTrackerTest { final String truth; final PersonTracker.Detection detection; + Labelled(PersonTracker.Box box, float score) { + truth = "A"; + detection = new PersonTracker.Detection(box, score); + } + Labelled(String truth, double center, float score) { this.truth = truth; float x = (float) center; @@ -72,6 +78,16 @@ public final class PersonTrackerTest { for (int i = 0; i < 39; i++) moving.frame(a(.18 + i*.015)); moving.check("Traverse camera", 1,0,0,0,0); + Scenario approach = new Scenario(); + approach.step = 333; + for (int i = 0; i < 31; i++) { + float distance = 5 - 4 * i / 30f; + float halfWidth = .22f / distance, personHeight = .82f / distance; + approach.frame(new Labelled(new PersonTracker.Box(.48f - halfWidth, .93f - personHeight, + .48f + halfWidth, .93f), .90f)); + } + approach.check("Approach from 5 m to 1 m at 3 FPS", 1, 0, 0, 0, 0); + Scenario crossing = new Scenario(); crossing.repeat(8, a(.2), b(.8)); for (int i = 0; i <= 24; i++) {