update examples to fix path issues
This commit is contained in:
@@ -11,7 +11,6 @@ from typing import Any, Optional
|
||||
import cv2
|
||||
import numpy as np
|
||||
import orisys
|
||||
from orisys.signal_processing import calibrate_normal_force
|
||||
|
||||
from .roi_geometry import (
|
||||
build_roi_warp,
|
||||
@@ -23,6 +22,10 @@ from .roi_geometry import (
|
||||
)
|
||||
|
||||
|
||||
NORMAL_FORCE_CAL_SLOPE = 3.92685554668795e-05
|
||||
NORMAL_FORCE_CAL_OFFSET = 0.0217596967278535
|
||||
|
||||
|
||||
@dataclass
|
||||
class FrameSnapshot:
|
||||
"""Normalized per-frame payload consumed by the Qt viewer."""
|
||||
@@ -46,6 +49,11 @@ class FrameSnapshot:
|
||||
record_frame: Optional[np.ndarray] = None
|
||||
|
||||
|
||||
def calibrate_normal_force(raw_value: float) -> float:
|
||||
"""Convert raw normal-force reading to Newtons using y = mx + c."""
|
||||
return NORMAL_FORCE_CAL_SLOPE * float(raw_value) + NORMAL_FORCE_CAL_OFFSET
|
||||
|
||||
|
||||
class SensorAdapter(ABC):
|
||||
"""Common interface between Qt and concrete sensor backends."""
|
||||
|
||||
@@ -76,37 +84,11 @@ def _bgr_from_gray_or_bgr(img: np.ndarray) -> np.ndarray:
|
||||
return img
|
||||
|
||||
|
||||
def _resolve_calibration_sensor_name(config_name) -> str | None:
|
||||
"""Map a config path/name to a sensors/<name> bundle when one exists."""
|
||||
if config_name is None:
|
||||
return None
|
||||
from orisys.configs import resolve_sensor_bundle
|
||||
|
||||
text = str(config_name).strip()
|
||||
if not text:
|
||||
return None
|
||||
|
||||
path = Path(text)
|
||||
parts = path.parts
|
||||
if "sensors" in parts:
|
||||
idx = parts.index("sensors")
|
||||
if idx + 1 < len(parts):
|
||||
candidate = parts[idx + 1]
|
||||
if resolve_sensor_bundle(candidate) is not None:
|
||||
return candidate
|
||||
|
||||
stem = path.stem if path.suffix else text
|
||||
if resolve_sensor_bundle(stem) is not None:
|
||||
return stem
|
||||
return None
|
||||
|
||||
|
||||
def _snapshot_from_sensor(
|
||||
sensor,
|
||||
*,
|
||||
raw_image=None,
|
||||
processed_image=None,
|
||||
sensor_name: str | None = None,
|
||||
) -> Optional[FrameSnapshot]:
|
||||
"""Build a FrameSnapshot with HHD/forces refreshed every frame."""
|
||||
if sensor is None or sensor.img is None:
|
||||
@@ -150,9 +132,6 @@ def _snapshot_from_sensor(
|
||||
below_threshold_color=(160, 160, 160),
|
||||
)
|
||||
|
||||
cal_name = sensor_name or _resolve_calibration_sensor_name(
|
||||
getattr(sensor, "config_name", None)
|
||||
)
|
||||
fn_raw = float(fnormal)
|
||||
return FrameSnapshot(
|
||||
image=image_bgr,
|
||||
@@ -163,7 +142,7 @@ def _snapshot_from_sensor(
|
||||
normal_force=fn_raw,
|
||||
shear_x=float(fshearx),
|
||||
shear_y=float(fsheary),
|
||||
normal_force_calibrated=calibrate_normal_force(fn_raw, sensor_name=cal_name),
|
||||
normal_force_calibrated=calibrate_normal_force(fn_raw),
|
||||
fps=float(fps),
|
||||
timestamp=time.time(),
|
||||
raw_image=raw_image,
|
||||
@@ -227,7 +206,6 @@ class OrisysSensorAdapter(SensorAdapter):
|
||||
if self.sensor.frame is not None
|
||||
else None,
|
||||
processed_image=_bgr_from_gray_or_bgr(self.sensor.img),
|
||||
sensor_name=_resolve_calibration_sensor_name(self.config_name),
|
||||
)
|
||||
|
||||
def reset(self) -> None:
|
||||
@@ -304,7 +282,6 @@ class Dd06RoiAdapter(SensorAdapter):
|
||||
self.sensor,
|
||||
raw_image=frame,
|
||||
processed_image=rectified,
|
||||
sensor_name=_resolve_calibration_sensor_name(self.config_name),
|
||||
)
|
||||
|
||||
def reset(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user