SDKPython 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 AlgorithmsConfig.capture when the Sdk is created. Choose the setting by intent:

IntentSetting
Let the SDK show motion prompts in an interactive terminalinteraction=CaptureInteractionMode.AUTO_TERMINAL
Let a GUI, ROS2 node, or remote program present prompts and controlsinteraction=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:

from qnbot_sdk import (
    AlgorithmsConfig,
    CaptureConfig,
    CaptureInteractionMode,
    Sdk,
)

sdk = Sdk(
    devices=(device_config,),
    targets=(target_config,),
    algorithms=AlgorithmsConfig(
        capture=CaptureConfig(
            interaction=CaptureInteractionMode.AUTO_TERMINAL,
            force=True,
            operator_id="operator-a",
        ),
    ),
)

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=("<package-id>",)
Look up and store results for a specific weareroperator_id="operator-a"
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:

session = device.start_capture(
    package_ids=(),
    operator_id="operator-a",
    force=True,
)

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.

session = device.start_capture(package_ids=(), operator_id="operator-a")

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):

readiness = device.capture_status(
    package_ids=(),
    operator_id="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:

from qnbot_sdk.glove import CaptureStageState

progress = device.capture_progress()
control = device.capture_control()

def on_progress(sample) -> None:
    stage = sample.value.stage
    render_prompt(stage.prompt, stage.collected_sample_count,
                  stage.required_sample_count)
    if (stage.state is not CaptureStageState.AWAITING_CONFIRMATION
            or stage.request_id is None):
        return
    control.confirm(stage.request_id)

progress.subscribe(on_progress)

render_prompt() 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 CaptureProgress 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 the guidance and 30-frame requirement 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.

With interaction set to external, a GUI, ROS2 node, or other program displays prompts and calls confirm(), skip(), retry(), or cancel() through the glove control interface. The SDK still handles capture and calibration; see Calibration for each target's status.

The snippet uses the device_config and target_config defined above. Your application supplies the UI functions and event loop. See the complete external_input_run_background.py example:

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

from qnbot_sdk import (
    AlgorithmsConfig,
    CalibrationReadinessState,
    CaptureConfig,
    CaptureInteractionMode,
    Sample,
    Sdk,
)
from qnbot_sdk.glove import (
    CalibrationProgress,
    CaptureProgress,
    CaptureStageState,
)

sdk = Sdk(
    devices=(device_config,),
    targets=(target_config,),
    algorithms=AlgorithmsConfig(
        capture=CaptureConfig(
            interaction=CaptureInteractionMode.EXTERNAL,
        ),
    ),
)
glove = sdk.glove()
device = glove.device()
readiness = device.calibration_status(name="dexhand")
if readiness.state is CalibrationReadinessState.NEEDS_CALIBRATION:
    open_calibration_ui(readiness.operator_id)
capture_progress = device.capture_progress()
calibration_progress = device.calibration_progress(name="dexhand")
control = device.capture_control()

def on_confirm(request_id: str) -> None:
    control.confirm(request_id)

def on_cancel(request_id: str) -> None:
    control.cancel(request_id)

def render_capture(sample: Sample[CaptureProgress]) -> None:
    value = sample.value
    stage = value.stage
    render_prompt(stage.prompt, stage.collected_sample_count,
                  stage.required_sample_count)
    if stage.request_id is None:
        return
    if stage.state is CaptureStageState.AWAITING_CONFIRMATION:
        bind_waiting_actions(
            request_id=stage.request_id,
            on_confirm=on_confirm,
            on_cancel=on_cancel,
        )
    else:
        bind_cancel_action(stage.request_id, on_cancel)

def render_calibration(sample: Sample[CalibrationProgress]) -> None:
    render_calibration_job(sample.value.job)

capture_progress.subscribe(render_capture)
calibration_progress.subscribe(render_calibration)

glove.start()
glove.run_background()
try:
    run_application_event_loop()
finally:
    glove.request_stop()
    glove.join()
    glove.close()

Starting capture manually

When you need to decide for yourself when to query and start capture, select the target device first and then explicitly call capture_status() and start_capture() on that GloveDevice. This approach directly controls when capture starts, unlike the external mode that only takes over the guided interaction. To start calibration manually on the same device, 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() in the API reference.

For a runnable example of the complete sequential capture of the left and right hands and then saving the calibration results separately by side, see host_capture_calibration.py.

Install external algorithm packages through the product CLI and configure them in the SDK before passing their IDs. Pass empty package_ids when only the included Skeleton is needed, and display the gestures from the returned eight-gesture capture plan.

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

from qnbot_sdk import Side
from qnbot_sdk.glove import (
    CaptureSessionState,
    CaptureStageState,
)

device = glove.device(side=Side.LEFT)
device.start(CalibrationMode.MANUAL)

readiness = device.capture_status(
    package_ids=(),
    operator_id="operator-a",
)
render_capture_readiness(readiness.state, readiness.plan, readiness.stages)

left_session = device.start_capture(
    package_ids=(),
    operator_id="operator-a",
    force=False,
)

while True:
    snapshot = left_session.snapshot()
    render_capture_plan(snapshot.plan, snapshot.stage_progress, snapshot.next_action)
    if snapshot.state is CaptureSessionState.COMPLETED:
        break
    if snapshot.state in (CaptureSessionState.FAILED, CaptureSessionState.CANCELLED):
        raise RuntimeError(snapshot.failure.message if snapshot.failure else "capture stopped")

    current = next(
        (stage for stage in snapshot.stage_progress
         if stage.stage_id == snapshot.current_stage),
        None,
    )
    if current is not None and current.state is CaptureStageState.AWAITING_CONFIRMATION:
        if snapshot.request_id is None:
            raise RuntimeError("capture confirmation has no request_id")
        input("Complete the prompted motion, then press Enter: ")
        left_session.confirm(snapshot.request_id)
        continue
    glove.update().sleep()

capture_result = left_session.result()
if capture_result is None:
    raise RuntimeError("completed capture has no result")

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

A CaptureSession executes the complete plan for one hand at a time. Two Sessions must be created sequentially for the left and right hands, and capture is not interleaved. Before the Session is complete, result() returns None; after completion it returns the capture summary. Subsequent calibration directly passes in the completed Session that is still open, with no 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 the render_* functions. 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

  • 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 create_capture_quality_session(side, device_model=...) from qnbot_sdk.glove. No Sdk instance, device startup, or CaptureSession is required. Passing only side defaults to 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:

from qnbot_sdk.glove import (
    CalibrationMode,
    CaptureQualityAction,
    GloveFinger,
    GloveHandPose,
)

# Online check: verified device selects the hand side and detector model
with device.create_capture_quality_session() as detector:
    device.start(CalibrationMode.NONE)
    required = detector.required_sample_count()  # currently 30 frames

    for stage_id in ("close", "open"):
        wait_for_stable_pose(stage_id)
        window: list[GloveHandPose] = collect_fresh_valid_hand_window(
            device, glove, required, GloveFinger
        )
        feedback = detector.assess_stage(stage_id, window)
        if not feedback.accepted:
            show_reason(feedback.reason, feedback.reason_en)
            if feedback.action is 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()

Key rules

  • Results vs. errors: Normal gesture rejection is returned as CaptureQualityFeedback(accepted=False, ...), not raised as an exception. Unknown stage_id, wrong window length, mixed hand/session identity, a closed session, or detector execution errors raise 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: Use one CaptureQualitySession sequentially for one operator and one physical hand. Call reset() when switching operator or glove, after reconnection, or before a new round, and call close() (or use with) when finished.

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