Focus distant face detection on the tracked person

This commit is contained in:
EVA x10 Development 2026-11-25 11:41:16 +01:00
parent 1799a299c8
commit 8ec2452dcd
6 changed files with 59 additions and 18 deletions

View File

@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.it_screen.edgevision" android:versionCode="23" android:versionName="0.3.18">
package="com.it_screen.edgevision" android:versionCode="24" android:versionName="0.3.19">
<uses-sdk android:minSdkVersion="30" android:targetSdkVersion="34"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera.any" android:required="true"/>

View File

@ -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.

View File

@ -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

View File

@ -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<Face> faces = detector.detect(frame, config.detection);
Rect faceRegion = faceSearchRegion(frame);
List<Face> 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<PersonTracker.Track, Face> associateFaces(List<Face> faces) {
Map<PersonTracker.Track, Face> result = new LinkedHashMap<>();
for (Face face : faces) {

View File

@ -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<Face> 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<String,float[]> result = run(frame, null, new RectF(0, 0, drawnWidth, drawnHeight));
return detect(frame, threshold, new Rect(0, 0, frame.getWidth(), frame.getHeight()));
}
List<Face> 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<String,float[]> result = run(frame, crop, new RectF(0, 0, drawnWidth, drawnHeight));
List<Face> 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));

View File

@ -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<String, Integer> 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++) {