SDKC++ SDK

Capture

What capture does, the guided interaction, capture progress and control, and starting capture manually.

Current version · 2.0.0

Capture

Connect the device before starting capture.

When recapture is not forced (force=false) and capture requirements and samples are unchanged, complete reuse retains the original capture record and existing compatible calibration; reuse alone does not trigger recalibration.

Hand capture gestures

Hold each gesture below until 30 frames have been collected. All eight stages are required and use this order by default; the wearer cannot skip a stage, although stages already satisfied by a compatible earlier capture are reused instead of repeated. Even when an algorithm uses only a subset, the SDK collects the complete pool for reuse by compatible algorithms.

StageGesture
closeHold five fingers straight and together, relaxed (do not make a fist)
openHold all five fingers straight and spread, without strain
mcp90Four MCPs bent ~90 deg, other joints straight, thumb relaxed; hold
mcp90_pip90Four MCPs/PIPs bent palmward, DIPs near straight, thumb relaxed; hold
pinch_firstHold thumb and index pads together gently, without squeezing
pinch_middleHold thumb and middle pads together gently, without squeezing
pinch_ringHold thumb and ring pads together gently, without squeezing
pinch_littleHold 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 for mcp90; bend both MCP and PIP while keeping DIPs near straight for mcp90_pip90. Render prompt / prompt_en returned by the plan and progress directly.

Compatible stages with enough samples can be reused; missing or incompatible stages must still be completed. Use the readiness returned by capture_status() and calibrate each target separately afterward.

Capture configuration

Automatic flow

The default automatic flow reads its capture settings from SdkConfig::algorithms.capture when the Sdk is created. Choose the setting by intent:

IntentSetting
Let the SDK show motion prompts in an interactive terminalinteraction = qnbot::CaptureInteractionMode::auto_terminal
Let a GUI, ROS2 node, or remote program present prompts and controlsinteraction = qnbot::CaptureInteractionMode::external
Ignore reusable capture data and collect every required sample againforce = true
Look up and store results separately for each weareroperator_id = "operator-a"

For example, use the built-in terminal guidance and force a complete recapture for operator-a:

qnbot::SdkConfig config;
config.devices = {device_config};
config.targets = {target_config};
config.algorithms.capture.interaction =
    qnbot::CaptureInteractionMode::auto_terminal;
config.algorithms.capture.force = true;
config.algorithms.capture.operator_id = "operator-a";

qnbot::Sdk sdk(std::move(config));

See CaptureConfig for field types, defaults, and constraints.

Manual flow

The manual flow provides the settings for this capture directly in the start_capture() call:

IntentParameter
Select this run's algorithm packages; an empty sequence uses the included Skeleton capture plan, and the eight-gesture set stays the samepackage_ids
Look up and store results for a specific weareroperator_id
Ignore reusable capture data and collect every required sample againforce = true

For example, use the configured included Skeleton to force a complete recapture for operator-a:

const bool force_recapture = true;
auto session = device.start_capture(
    {}, "operator-a", force_recapture);

Pass package_ids explicitly: an empty sequence {} selects the included Skeleton capture plan configured on the started device, without an external algorithm package. For a non-empty sequence, every ID must be non-empty and refer to a package used in the current SDK configuration; installation alone is insufficient. An unavailable included Skeleton causes an error.

auto session = device.start_capture({}, "operator-a", false);

If you only want to recompute calibration from existing capture data, first see the distinction between the two force settings in Overview.

Capture status and control

The default automatic flow checks and advances capture on its own, so it does not need these APIs. Use them only when taking control:

  • Application-controlled start: capture_status() → inspect the state → start_capture().
  • External UI guidance: capture_progress() → show the current action → capture_control().

Decide whether to start manual capture

First check whether the wearer still needs capture for the plan selected by package_ids (empty for the included Skeleton):

const auto readiness = device.capture_status({}, "operator-a");
render_capture_readiness(readiness.state, readiness.plan, readiness.stages);

Choose the next step from readiness.state:

StateNext step
needs_captureCall start_capture() to create a capture session
readyReuse the existing capture and continue to calibration
not_requiredSkip capture for this selection and continue

Use plan and stages to show this run to the wearer. See CaptureReadiness for complete fields and Starting capture manually for the start code.

Advance capture from an external UI

Subscribe to progress, render the current action, and respond with identifiers from that same progress update:

auto progress = device.capture_progress();
auto control = device.capture_control();
auto subscription = progress.subscribe(
    [&](const qnbot::Sample<qnbot::CaptureProgress>& sample) {
        const auto& stage = sample.value.stage;
        render_capture(stage);
        if (stage.state !=
                qnbot::CaptureStageState::awaiting_confirmation ||
            !stage.request_id) return;
        control.confirm(*stage.request_id);
    });

render_capture() is your custom UI renderer. Beyond confirming the current motion, you can trigger a retry (control.retry(stage_id)) or cancel (control.cancel(request_id)) using identifiers from the latest progress update. See External takeover of guided interaction for the full example and Capture models for field details.

Select another motion or repeat capture

During an active manual capture session, use a stage_id from the plan to jump to a pending motion or re-capture a completed or skipped one:

session.retry(stage_id);

Switching discards unfinished frames from the current motion while keeping all other completed motions intact. Read the updated snapshot and confirm with its new request_id to collect the selected motion; once finished, the SDK automatically resumes the first remaining unfinished motion until all eight motions are collected.

Capture motions

The SDK captures the following fixed set of 8 gestures, with 30 frames per gesture, producing a reusable capture record once all eight finish. The motion set, order, and prompts are defined by the SDK regardless of installed or selected algorithm packages.

OrderGesture IDMotion
1closeHold five fingers straight and together, relaxed (do not make a fist)
2openHold all five fingers straight and spread, without strain
3mcp90Four MCPs bent ~90 deg, other joints straight, thumb relaxed; hold
4mcp90_pip90Four MCPs/PIPs bent palmward, DIPs near straight, thumb relaxed; hold
5pinch_firstHold thumb and index pads together gently, without squeezing
6pinch_middleHold thumb and middle pads together gently, without squeezing
7pinch_ringHold thumb and ring pads together gently, without squeezing
8pinch_littleHold thumb and little pads together gently, without squeezing

All eight motions are required (optional is false). Render step order, required_sample_count, and localized prompts (prompt / prompt_en) directly from the current plan and progress.

A complete valid capture is reused across algorithm packages for the same wearer, source, hand side, and verified glove. When switching packages, the SDK reuses a compatible calibration or fits a new one from the saved raw frames automatically. Keep the default force = false for normal use; set force = true to collect all 8 gestures again.

Capture methods

Guided capture interaction

The default auto_terminal guides capture in an interactive console. Background startup completes required guidance first, and automatic-policy manual update() also supports terminal guidance. Background startup returns first when any pending input is external; keep feeding frames during calibration and read target output after the result takes effect. Startup still waits when all pending inputs are device-fed. See the runtime notes for failure, cancellation, and cleanup, and Terminal output and interaction for console detection.

Example first step and completion message for the default Skeleton target (the other seven steps are omitted):

[Capture] glove.primary.right
close: Hold five fingers straight and together, relaxed
Press Enter to begin...
[####################] 30/30
[Calibration] glove.primary.right -> hand.primary.right completed

glove.primary.right identifies the right glove; hand.primary.right is its output target. After Enter, the progress bar updates on the same line; the SDK provides guidance and 30 frames per gesture from its eight-gesture plan. This excerpt shows the first step; the other seven complete before the target-calibration completion message appears. In non-interactive environments, use external mode for application-owned confirmation. Manual update follows the interaction rules above.

External takeover of guided interaction

None of the eight hand stages can be skipped. Offer skip() only when another capture plan reports stage.optional as true.

A GUI, ROS2, or remote program should choose external, subscribe to the source-scoped capture_progress(), and hand the current capture request unchanged to capture_control(). After Capture completes, the calibration status of each target is described in Calibration.

The following snippet continues from the device_config and target_config already created above; open_calibration_ui(), render_capture(), render_calibration_job(), bind_waiting_actions(), and bind_cancel_action() are provided by the application. For a complete example with the same external interaction and background cleanup flow, see external_input_run_background.cpp:

Run the linked external_input_run_background.cpp with --capture-interaction external to match this section; the example defaults to SDK terminal guidance.

qnbot::SdkConfig config;
config.devices = {device_config};
config.targets = {target_config};
config.algorithms.capture.interaction =
    qnbot::CaptureInteractionMode::external;
config.algorithms.capture.operator_id = "operator-42";

qnbot::Sdk sdk(std::move(config));
auto glove = sdk.glove();
auto device = glove.device();
auto readiness = device.calibration_status("dexhand");
if (readiness.state ==
    qnbot::CalibrationReadinessState::needs_calibration) {
    open_calibration_ui(readiness.operator_id);
}
auto capture_progress = device.capture_progress();
auto calibration_progress = device.calibration_progress("dexhand");
auto control = device.capture_control();
auto on_confirm = [&control](const std::string& request_id) {
    control.confirm(request_id);
};
auto on_cancel = [&control](const std::string& request_id) {
    control.cancel(request_id);
};
auto capture_subscription = capture_progress.subscribe(
    [&](const qnbot::Sample<qnbot::CaptureProgress>& sample) {
        render_capture(sample.value.stage);
        if (!sample.value.stage.request_id) return;
        if (sample.value.stage.state ==
            qnbot::CaptureStageState::awaiting_confirmation) {
            bind_waiting_actions(*sample.value.stage.request_id,
                                 on_confirm, on_cancel);
        } else {
            bind_cancel_action(*sample.value.stage.request_id, on_cancel);
        }
    });
auto calibration_subscription = calibration_progress.subscribe(
    [](const qnbot::Sample<qnbot::CalibrationProgress>& sample) {
        render_calibration_job(sample.value.job);
    });

For the definitions and constraints of CaptureInteractionMode and operator_id, see CaptureConfig.

Starting capture manually

Applications that need to split capture into its own business stage should use the separate capture flow and explicitly call capture_status() and start_capture() on the selected GloveDevice; for the calibration side after capture completes, see Starting calibration manually.

For the start parameters and the minimal forced-recapture call, see Manual flow under Capture configuration.

Capture and calibration use the same device, and the entire capture completes before calibration starts. The loop keeps reading the state of the same session; it does not create the session again. Calibration receives the completed capture session while it is still open; close created sessions on failure, cancellation, or timeout:

Rendering diagram

For the parameters, types, and defaults, see GloveDevice::start_capture().

For a complete runnable example that captures the left and right hands in sequence and then saves the calibration result per side, see host_capture_calibration.cpp.

Pass empty package_ids for included Skeleton capture. For external packages, install them through the product CLI and configure them in the SDK before passing their IDs. Display gestures from the returned capture plan.

First query the readiness with capture_status(), then start the capture; capture_status() does not create a Session. Capture and the subsequent calibration must use the same GloveDevice:

auto device = glove.device(qnbot::Side::left);
device.start(qnbot::CalibrationMode::manual);

auto readiness = device.capture_status(
    {}, "operator-a");
render_capture_readiness(readiness.state, readiness.plan, readiness.stages);

const bool force_recapture = true;
auto left_session = device.start_capture(
    {}, "operator-a", force_recapture);
while (true) {
    const auto snapshot = left_session.snapshot();
    render_capture_plan(snapshot.plan, snapshot.stage_progress, snapshot.next_action);
    if (snapshot.state == qnbot::CaptureSessionState::completed) break;
    if (snapshot.state == qnbot::CaptureSessionState::failed ||
        snapshot.state == qnbot::CaptureSessionState::cancelled)
        throw std::runtime_error("capture stopped");

    const auto current = std::find_if(
        snapshot.stage_progress.begin(), snapshot.stage_progress.end(),
        [&](const auto& stage) {
            return snapshot.current_stage &&
                   stage.stage_id == *snapshot.current_stage;
        });
    if (current != snapshot.stage_progress.end() &&
        current->state == qnbot::CaptureStageState::awaiting_confirmation) {
        if (!snapshot.request_id)
            throw std::runtime_error("capture request_id is missing");
        wait_for_operator_confirmation();
        left_session.confirm(*snapshot.request_id);
        continue;
    }
    static_cast<void>(glove.update().sleep());
}
auto capture_result = left_session.result();
if (!capture_result)
    throw std::runtime_error("completed capture has no result");

For the complete fields, types, and nullability, see CaptureReadiness, CaptureSessionSnapshot, and CaptureResult.

A CaptureSession executes the complete plan for one hand at a time. The left and right hands must be created as two Sessions in sequence, with no interleaved capture. Before completion, result() returns std::nullopt; after completion, it returns the capture summary. Subsequent calibration passes the completed Session, which is still kept open, directly, so the application does not need to touch raw frame files or SDK-internal identifiers; see Starting calibration manually.

capture_status() queries whether the current plan still needs capture and does not create a Session; only start_capture() starts the actual session. For the next step from each state, see Decide whether to start manual capture.

The snippets show the main flow; the application supplies render_* and wait_for_operator_confirmation(). Set a timeout and close Sessions on cancellation or failure. Confirm all eight required stages; use retry(stage_id) to repeat a stage. The linked runnable example includes interaction, timeouts, and resource cleanup.

With the SDK version described above, the linked runnable example accepts Enter to capture, stage <stage_id> to select a motion, and n to cancel while awaiting confirmation. The prompt lists stage IDs and their states. Every required motion still needs its full samples.

Standalone capture quality check

Standalone capture quality checking is decoupled from CaptureSession. The application creates a quality session, collects a complete window from the hand pose stream, calls assess_stage(), and acts on the returned feedback to retry, retain manually, or advance. Existing CaptureConfig, capture_status(), start_capture(), and start_calibration() calls are unchanged.

Relationship to existing capture

  • Standalone quality checking evaluates 30-frame hand-pose windows supplied by your application and returns feedback, while capture flow control (CaptureSession), confirmations, sample storage, and calibration remain handled by the existing capture and calibration APIs.
  • Quality checking is optional. To skip it, complete the eight required capture stages normally and call device.start_calibration(capture_session, targets); your application can track unchecked, passed, and manually retained samples separately.

Creating a quality session

Include <qnbot/glove.hpp> to access the following entry points:

  • Online device (recommended): Call device.create_capture_quality_session(). The SDK selects the detector from the verified device identity and hand side so online applications do not need to maintain a device-model mapping.
  • Playback, external input, or explicit model override: Call qnbot::create_capture_quality_session(side) or qnbot::create_capture_quality_session(side, device_model). No Sdk instance, device startup, or CaptureSession is required. Passing only side defaults to qnbot::CaptureQualityDeviceModel::standard (options: standard, hmp_mx, helix).

Collecting a 30-frame window and handling feedback

Read the required window size from required_sample_count() (currently 30 frames). Once the wearer holds a steady posture, collect 30 fresh, valid GloveHandPose frames for the same physical hand from payload.hand of device.pose() (local fingertip positions in meters, XYZW quaternions, and actual hand side, validity, and timing). Quality checking evaluates complete 30-frame hand-pose windows.

Assess close first to establish the session's reference, then assess any other stages the application needs:

#include <qnbot/glove.hpp>

// Online check: verified device selects the hand side and detector model
auto detector = device.create_capture_quality_session();
device.start(qnbot::CalibrationMode::none);
const std::size_t required = detector.required_sample_count();  // currently 30 frames

for (const std::string stage_id : {"close", "open"}) {
    wait_for_stable_pose(stage_id);
    const std::vector<qnbot::GloveHandPose> window =
        collect_fresh_valid_hand_window(device, required);
    const auto feedback = detector.assess_stage(stage_id, window);
    if (!feedback.accepted) {
        show_reason(feedback.reason, feedback.reason_en);
        if (feedback.action ==
            qnbot::CaptureQualityAction::recapture_reference) {
            // Recapture the close reference; recapture dependent stages if invalidated
            restart_from_close();
            break;
        }
        if (operator_chooses_manual_retain()) {
            // Retain the latest rejected valid window; feedback.accepted stays false
            detector.skip_stage(stage_id);
            record_manual_retain(stage_id);
            if (stage_id == "close") {
                clear_dependent_stage_windows();
            }
        } else {
            retry_current_stage(stage_id);
            break;
        }
    }
}
detector.reset();
detector.close();

Key rules

  • Results vs. errors: Normal gesture rejection is returned as CaptureQualityFeedback (accepted == false), not thrown as an exception. Unknown stage_id, wrong window length, mixed hand/session identity, a closed session, or detector execution errors throw exceptions.
  • Structured advice: action is next, retry_stage, or recapture_reference; reset_dependent_stages indicates whether windows depending on the previous close reference are invalidated; reason and reason_en supply Chinese and English short messages.
  • Manual retention: skip_stage(stage_id) applies only to the most recently rejected valid window and leaves accepted as false. After retaining close, collect fresh windows for every dependent stage.
  • Lifecycle and reset: CaptureQualitySession is move-only and requires sequential access for one operator and one physical hand. Call reset() when switching operator or glove, after reconnection, or before a new round, and call close() when finished.

See CaptureQualitySession, CaptureQualityFeedback, and Migration for full signatures, fields, and upgrade steps.