Skip to main content

Post-Processing Mode

1. Live acquisitionRead images, depth, and force outputs from each captured frame.
2. Replay from runtimeExport a runtime from a calibrated sensor and use it to create a Solver for replay.
3. Replay by sensor modelCreate a Solver by sensor model, calibrate it with an unloaded image, and replay.

Live acquisition​

The SDK returns live data. The following example only acquires data in a loop; callers that need persistence must add their own file-writing logic:

from xensesdk import Sensor

sensor = Sensor.create("OP000064")
try:
while True:
rectify, depth = sensor.selectSensorInfo(
Sensor.OutputType.Rectify,
Sensor.OutputType.Depth,
)
finally:
sensor.release()

Offline replay​

Offline mode is suitable for regression testing and algorithm tuning. You can create a Solver from a runtime or a sensor model.

1. Replay from a runtime​

Export a runtime​

First export the runtime configuration from a connected and calibrated sensor:

sensor.exportRuntimeConfig(save_dir="runtime")
# Generates the runtime/runtime_<serial number> file
Protect runtime files

The runtime contains the configuration and reference image. Do not edit it manually or commit it to a public repository.

Replay using a runtime​

Use the runtime configuration for the same sensor, an unloaded reference image, and the image to be processed:

import cv2
from xensesdk import Sensor

solver = Sensor.createSolver("runtime/runtime_<serial number>")
try:
reference = cv2.imread("reference.png") # Unloaded rectified image
image = cv2.imread("frame.png")
if reference is None or image is None:
raise RuntimeError("Please provide reference.png and frame.png")
solver.calibrateSensor(rectify_image=reference)
force_resultant, difference, depth = solver.selectSensorInfo(
Sensor.OutputType.ForceResultant,
Sensor.OutputType.Difference,
Sensor.OutputType.Depth,
rectify_image=image,
)
print(depth.shape, depth.dtype)
finally:
solver.release()

2. Replay by creating a Solver​

You do not need to export a runtime. Create a Solver directly by sensor model, calibrate it with an unloaded rectified image from that model, then provide the rectified image to be processed:

import cv2
from xensesdk import Sensor

solver = Sensor.createSolver(sensor_type="OG")
try:
reference = cv2.imread("reference.png") # Unloaded rectified image
image = cv2.imread("frame.png")
if reference is None or image is None:
raise RuntimeError("Please provide reference.png and frame.png")
solver.calibrateSensor(rectify_image=reference)
force_resultant, difference, depth = solver.selectSensorInfo(
Sensor.OutputType.ForceResultant,
Sensor.OutputType.Difference,
Sensor.OutputType.Depth,
rectify_image=image,
)
print(depth.shape, depth.dtype)
finally:
solver.release()

Images read by OpenCV are in BGR format. When passing images, choose either raw_image or rectify_image according to the processing required. To ensure reproducible results, keep the input frame order consistent and record the SDK, model, and configuration versions.

More code examplesSee how to export a runtime, feed rectified images to the Solver frame by frame, and visualize inference results.
Open GitHub example ↗