Capture
Android Java SDK: Capture
Capture
For in-app capture prompts, pass new CaptureConfig(CaptureInteractionMode.EXTERNAL, false, operatorId) in AlgorithmsConfig before creating the SDK. Use a stable operator ID for the wearer.
Follow the current plan
Subscribe to device.captureProgress(). Prefer promptEn for an English UI and fall back to prompt when it is null. Transfer state from the callback to the main thread for display. An explicit capture session can read the same stages, prompts, sample counts and allowed operations from CaptureSessionSnapshot.
The excerpt below is the captureSide method from HostCaptureCalibration.java; the public run calls it once for each hand. It reads CaptureSessionSnapshot and submits only confirmations allowed by allowedOperations; completion returns the still-open session, while failure or cancellation cancels and closes it.
// Excerpt from examples-public/examples/glove/java/src/main/java/com/qnbot/examples/HostCaptureCalibration.java (captureSide)
import com.qnbot.sdk.SleepResult;
import com.qnbot.sdk.glove.Glove;
import com.qnbot.sdk.glove.GloveDevice;
import com.qnbot.sdk.glove.capture.CaptureControlAction;
import com.qnbot.sdk.glove.capture.CaptureSession;
import com.qnbot.sdk.glove.capture.CaptureSessionSnapshot;
import com.qnbot.sdk.glove.capture.CaptureSessionState;
import com.qnbot.sdk.glove.capture.CaptureStageProgress;
import com.qnbot.sdk.glove.capture.CaptureStageState;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;
public final class HostCaptureCalibration {
private HostCaptureCalibration() {}
private static CaptureSession captureSide(GloveDevice device, Glove glove,
List<String> packages, boolean force, Predicate<String> confirm, BooleanSupplier cancelled)
throws InterruptedException {
System.out.println(
device.name() + " readiness=" + device.captureStatus(packages, "default").state);
CaptureSession capture = device.startCapture(packages, "default", force);
boolean completed = false;
try {
long deadline = System.nanoTime() + 300_000_000_000L;
Set<String> confirmed = new HashSet<>();
long nextProgressAt = 0;
while (!cancelled.getAsBoolean()) {
CaptureSessionSnapshot snapshot = capture.snapshot();
if (snapshot.state == CaptureSessionState.COMPLETED) {
capture.result().orElseThrow(
() -> new IllegalStateException("Completed capture has no result"));
completed = true;
return capture;
}
if (snapshot.state == CaptureSessionState.FAILED
|| snapshot.state == CaptureSessionState.CANCELLED) {
throw new IllegalStateException(
snapshot.failure == null ? "Capture stopped" : snapshot.failure.message);
}
if (System.nanoTime() >= nextProgressAt) {
System.out.println(device.name() + " capture=" + snapshot.state + " stage="
+ snapshot.currentStage + " samples=" + snapshot.collectedSampleCount + "/"
+ snapshot.requiredSampleCount);
nextProgressAt = System.nanoTime() + 500_000_000L;
}
if (snapshot.requestId != null && !confirmed.contains(snapshot.requestId)
&& snapshot.allowedOperations.contains(CaptureControlAction.CONFIRM)) {
for (CaptureStageProgress stage : snapshot.stageProgress) {
if (stage.stageId.equals(snapshot.currentStage)
&& stage.state == CaptureStageState.AWAITING_CONFIRMATION) {
if (confirm.test(device.name() + " " + stage.prompt)) {
capture.confirm(snapshot.requestId);
confirmed.add(snapshot.requestId);
}
}
}
}
if (System.nanoTime() >= deadline) {
throw new IllegalStateException("Capture timed out");
}
var update = glove.update();
if (!update.hasNextTask) {
Thread.sleep(10);
} else if (update.sleep() == SleepResult.STOPPED) {
break;
}
}
if (cancelled.getAsBoolean()) {
throw new CancellationException("Capture cancelled by caller");
}
throw new IllegalStateException("Capture stopped");
} finally {
if (!completed) {
try {
CaptureSessionState state = capture.snapshot().state;
if (state != CaptureSessionState.COMPLETED && state != CaptureSessionState.FAILED
&& state != CaptureSessionState.CANCELLED) {
capture.cancel();
}
} finally {
capture.close();
}
}
}
}
}Render stage IDs, order, prompts, sample counts, and optionality dynamically from the capture plan; skip the capture UI when the plan is empty. Hand capture uses the following eight required motions (30 frames each, optional is false):
| Stage | Gesture |
|---|---|
close | Hold five fingers straight and together, relaxed (do not make a fist) |
open | Hold all five fingers straight and spread, without strain |
mcp90 | Four MCPs bent ~90 deg, other joints straight, thumb relaxed; hold |
mcp90_pip90 | Four MCPs/PIPs bent palmward, DIPs near straight, thumb relaxed; hold |
pinch_first | Hold thumb and index pads together gently, without squeezing |
pinch_middle | Hold thumb and middle pads together gently, without squeezing |
pinch_ring | Hold thumb and ring pads together gently, without squeezing |
pinch_little | Hold thumb and little pads together gently, without squeezing |
- Joint terms: MCP is the knuckle joint, PIP is the middle joint, and DIP is the fingertip joint; "four fingers" refers to the index, middle, ring, and little fingers.
- Posture notes: keep all five fingers straight and together for
close; bend only the four MCP joints formcp90; bend both MCP and PIP while keeping DIPs near straight formcp90_pip90. Renderprompt/promptEnreturned by the plan and progress directly.
Automatic workflow and explicit sessions
For the normal startup workflow, respond to progress with device.captureControl().confirm(requestId), skip(requestId), retry(stageId) or cancel(requestId).
To separate capture and calibration under app control, select the target and use device.start(CalibrationMode.MANUAL), then start the runtime loop. Call captureStatus(packageIds, operatorId) and startCapture(packageIds, operatorId, force). Obtain packageIds from your delivery instructions and use a nonempty app-selected operator identifier; do not copy another product's package identifiers.
Keep the returned CaptureSession open through calibration. Read snapshot(), enable only its allowedOperations, and submit the currently displayed requestId or stageId. result() is empty before completion. Failure and cancellation are not successful completion. Continue to Calibration only after state == CaptureSessionState.COMPLETED. Close subscriptions and sessions when finished.
In a running manual session, call session.retry(stageId) to select a pending, completed, or skipped stage. Show the new request and confirm it before sampling. Switching discards only unfinished samples from the interrupted stage and previous samples of the selected stage. Complete every required stage before starting calibration.
Standalone capture quality check
Standalone capture quality checking evaluates 30-frame hand-pose windows supplied by your app and returns feedback, while capture flow control (CaptureSession), confirmations, sample storage, and calibration remain handled by the existing capture and calibration APIs. To skip gesture quality checking, complete the eight required capture stages normally and call device.startCalibration(captureSession, targets).
- Online device (recommended): Call
device.createCaptureQualitySession()so the SDK selects the detector from the verified device identity and hand side. - Playback, external input, or explicit model override: Call
Sdk.initialize(context)on a worker thread first, then callCaptureQualitySession.createCaptureQualitySession(side)(defaults toCaptureQualityDeviceModel.STANDARD) orCaptureQualitySession.createCaptureQualitySession(side, deviceModel)(STANDARD,HMP_MX, orHELIX) without creating anSdkorCaptureSession.
Read the window size from requiredSampleCount() (currently 30 frames) and collect 30 fresh, valid GloveHandPose frames for the same hand from payload.hand of device.pose() (local fingertip positions in meters and quaternionXyzw). Assess close first to establish the reference, then assess any other stages needed:
import com.qnbot.sdk.config.Side;
import com.qnbot.sdk.error.UnavailableFeatureException;
import com.qnbot.sdk.glove.GloveDevice;
import com.qnbot.sdk.glove.GloveHandPose;
import com.qnbot.sdk.glove.capture.CaptureQualityAction;
import com.qnbot.sdk.glove.capture.CaptureQualityDeviceModel;
import com.qnbot.sdk.glove.capture.CaptureQualityFeedback;
import com.qnbot.sdk.glove.capture.CaptureQualitySession;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Supplier;
public final class CaptureQuality {
private CaptureQuality() {}
public static void checkStage(
GloveDevice device,
Side side,
CaptureQualityDeviceModel modelOverride,
String stageId,
Supplier<List<GloveHandPose>> collectWindow,
BiPredicate<String, CaptureQualityFeedback> retainRejected) {
try (CaptureQualitySession detector =
modelOverride == null
? device.createCaptureQualitySession()
: CaptureQualitySession.createCaptureQualitySession(side, modelOverride)) {
long required = detector.requiredSampleCount();
for (String current : "close".equals(stageId) ? List.of("close") : List.of("close", stageId)) {
List<GloveHandPose> window = List.copyOf(collectWindow.get());
if (window.size() != required) {
throw new IllegalStateException("Expected " + required + " fresh valid hand frames");
}
CaptureQualityFeedback feedback = detector.assessStage(current, window);
if (!feedback.accepted) {
if (feedback.action == CaptureQualityAction.RECAPTURE_REFERENCE) {
break;
}
if (!retainRejected.test(current, feedback)) {
break;
}
detector.skipStage(current);
}
}
detector.reset();
} catch (UnavailableFeatureException unavailable) {
System.out.println("capture quality unavailable: " + unavailable.getMessage());
}
}
}Normal gesture rejection returns CaptureQualityFeedback with accepted == false, structured action, resetDependentStages, reason, and reasonEn. Unknown stageId, wrong window length, mixed hand/session identity, a closed session, or unavailable runtime throws an exception. skipStage(stageId) applies only to the most recently rejected valid window and leaves accepted as false; after retaining close, collect fresh windows for every dependent stage. Use one CaptureQualitySession sequentially, call reset() when switching operator or glove, and release it with try-with-resources or close().
See the Android API reference for signatures and Migration for upgrade and draft-withdrawal notes.