Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e4e8911001 | |||
| 4db82c890d |
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 MiB After Width: | Height: | Size: 2.0 MiB |
@@ -27,6 +27,10 @@ ORISYS_SRC = REPO.parent / "orisys-sdk" / "src"
|
|||||||
if ORISYS_SRC.is_dir() and str(ORISYS_SRC) not in sys.path:
|
if ORISYS_SRC.is_dir() and str(ORISYS_SRC) not in sys.path:
|
||||||
sys.path.insert(0, str(ORISYS_SRC))
|
sys.path.insert(0, str(ORISYS_SRC))
|
||||||
|
|
||||||
|
from sensor_bench.paths import prefer_local_sensor_bundles # noqa: E402
|
||||||
|
|
||||||
|
prefer_local_sensor_bundles(REPO)
|
||||||
|
|
||||||
from sensor_bench_operator.__main__ import main # noqa: E402
|
from sensor_bench_operator.__main__ import main # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ ORISYS_SRC = ROOT.parent / "orisys-sdk" / "src"
|
|||||||
if ORISYS_SRC.is_dir() and str(ORISYS_SRC) not in sys.path:
|
if ORISYS_SRC.is_dir() and str(ORISYS_SRC) not in sys.path:
|
||||||
sys.path.insert(0, str(ORISYS_SRC))
|
sys.path.insert(0, str(ORISYS_SRC))
|
||||||
|
|
||||||
|
from sensor_bench.paths import prefer_local_sensor_bundles # noqa: E402
|
||||||
|
|
||||||
|
prefer_local_sensor_bundles(ROOT)
|
||||||
|
|
||||||
from sensor_bench.main import main # noqa: E402
|
from sensor_bench.main import main # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,12 @@ os.environ.setdefault("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0")
|
|||||||
|
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
|
from .paths import app_root, prefer_local_sensor_bundles
|
||||||
|
|
||||||
|
|
||||||
def main(argv: list[str] | None = None) -> int:
|
def main(argv: list[str] | None = None) -> int:
|
||||||
|
prefer_local_sensor_bundles(app_root())
|
||||||
|
|
||||||
parser_args = list(sys.argv[1:] if argv is None else argv[1:])
|
parser_args = list(sys.argv[1:] if argv is None else argv[1:])
|
||||||
# Accept unknown Qt args (e.g. -platform offscreen) without advertising
|
# Accept unknown Qt args (e.g. -platform offscreen) without advertising
|
||||||
# internal-only flags on the public CLI.
|
# internal-only flags on the public CLI.
|
||||||
|
|||||||
@@ -129,6 +129,50 @@ def list_local_sensor_bundle_names() -> list[str]:
|
|||||||
return found
|
return found
|
||||||
|
|
||||||
|
|
||||||
|
_PREFERRED_SENSOR_ROOT: Path | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def prefer_local_sensor_bundles(root: Path | None = None) -> Path | None:
|
||||||
|
"""Make ``root/sensors`` win over packaged/SDK bundles for Orisys lookups.
|
||||||
|
|
||||||
|
Wraps ``orisys.configs._candidate_sensor_roots`` so consumer
|
||||||
|
``sensors/<name>/sensor.json`` and ``force_calibration.json`` resolve
|
||||||
|
before orisys-sdk or wheel copies. Idempotent.
|
||||||
|
"""
|
||||||
|
global _PREFERRED_SENSOR_ROOT
|
||||||
|
|
||||||
|
resolved_root = Path(root).resolve() if root is not None else app_root()
|
||||||
|
sensors = (resolved_root / "sensors").resolve()
|
||||||
|
if not sensors.is_dir():
|
||||||
|
return None
|
||||||
|
|
||||||
|
if _PREFERRED_SENSOR_ROOT is not None and _PREFERRED_SENSOR_ROOT == sensors:
|
||||||
|
return sensors
|
||||||
|
|
||||||
|
try:
|
||||||
|
import orisys.configs as configs
|
||||||
|
except Exception: # noqa: BLE001
|
||||||
|
return None
|
||||||
|
|
||||||
|
original = configs._candidate_sensor_roots
|
||||||
|
if getattr(original, "_sensor_bench_local_pref", None) == str(sensors):
|
||||||
|
_PREFERRED_SENSOR_ROOT = sensors
|
||||||
|
return sensors
|
||||||
|
|
||||||
|
def _candidate_sensor_roots_prefer_local() -> list[Path]:
|
||||||
|
roots = [sensors]
|
||||||
|
for candidate in original():
|
||||||
|
resolved = Path(candidate).resolve()
|
||||||
|
if resolved != sensors and resolved not in roots:
|
||||||
|
roots.append(resolved)
|
||||||
|
return roots
|
||||||
|
|
||||||
|
_candidate_sensor_roots_prefer_local._sensor_bench_local_pref = str(sensors) # type: ignore[attr-defined]
|
||||||
|
configs._candidate_sensor_roots = _candidate_sensor_roots_prefer_local
|
||||||
|
_PREFERRED_SENSOR_ROOT = sensors
|
||||||
|
return sensors
|
||||||
|
|
||||||
|
|
||||||
def _orisys_bundle_has_force_calibration(name: str) -> bool:
|
def _orisys_bundle_has_force_calibration(name: str) -> bool:
|
||||||
try:
|
try:
|
||||||
import orisys
|
import orisys
|
||||||
@@ -260,6 +304,9 @@ def list_orisys_configs() -> list[str]:
|
|||||||
continue
|
continue
|
||||||
if key.lower() in PRODUCT_BUNDLES:
|
if key.lower() in PRODUCT_BUNDLES:
|
||||||
continue
|
continue
|
||||||
|
mapped = LEGACY_STEM_TO_BUNDLE.get(key.lower())
|
||||||
|
if mapped and mapped.lower() in seen_stems:
|
||||||
|
continue
|
||||||
entries.append(key)
|
entries.append(key)
|
||||||
seen_stems.add(key.lower())
|
seen_stems.add(key.lower())
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
|
|||||||
@@ -262,6 +262,33 @@ def test_normalize_sensor_config_ref_prefers_bundle() -> None:
|
|||||||
assert normalize_sensor_config_ref("box") == str(local_json.resolve())
|
assert normalize_sensor_config_ref("box") == str(local_json.resolve())
|
||||||
|
|
||||||
|
|
||||||
|
def test_prefer_local_sensor_bundles_for_force_calibration() -> None:
|
||||||
|
import orisys
|
||||||
|
|
||||||
|
from sensor_bench.paths import app_root, prefer_local_sensor_bundles
|
||||||
|
|
||||||
|
root = app_root()
|
||||||
|
local_box = (root / "sensors" / "box").resolve()
|
||||||
|
local_cal = local_box / "force_calibration.json"
|
||||||
|
if not local_box.is_dir() or not local_cal.is_file():
|
||||||
|
return
|
||||||
|
|
||||||
|
preferred = prefer_local_sensor_bundles(root)
|
||||||
|
assert preferred == (root / "sensors").resolve()
|
||||||
|
|
||||||
|
# Second call must stay idempotent (no stacked wrappers).
|
||||||
|
assert prefer_local_sensor_bundles(root) == preferred
|
||||||
|
roots = orisys.configs._candidate_sensor_roots()
|
||||||
|
assert Path(roots[0]).resolve() == preferred
|
||||||
|
assert sum(1 for r in roots if Path(r).resolve() == preferred) == 1
|
||||||
|
|
||||||
|
bundle = orisys.configs.resolve_sensor_bundle("box")
|
||||||
|
assert bundle is not None
|
||||||
|
assert bundle.root == local_box
|
||||||
|
assert bundle.force_calibration_json is not None
|
||||||
|
assert bundle.force_calibration_json.resolve() == local_cal.resolve()
|
||||||
|
|
||||||
|
|
||||||
def test_roi_geometry_helpers() -> None:
|
def test_roi_geometry_helpers() -> None:
|
||||||
from sensor_bench.roi_geometry import build_roi_warp, order_quad_points, warp_roi_to_rectangle
|
from sensor_bench.roi_geometry import build_roi_warp, order_quad_points, warp_roi_to_rectangle
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -375,6 +402,7 @@ if __name__ == "__main__":
|
|||||||
test_default_config_prefers_box_bundle()
|
test_default_config_prefers_box_bundle()
|
||||||
test_legacy_config_force_calibration_fallback()
|
test_legacy_config_force_calibration_fallback()
|
||||||
test_normalize_sensor_config_ref_prefers_bundle()
|
test_normalize_sensor_config_ref_prefers_bundle()
|
||||||
|
test_prefer_local_sensor_bundles_for_force_calibration()
|
||||||
test_roi_geometry_helpers()
|
test_roi_geometry_helpers()
|
||||||
test_exhibition_window_offscreen()
|
test_exhibition_window_offscreen()
|
||||||
print("ok")
|
print("ok")
|
||||||
|
|||||||
Reference in New Issue
Block a user