From 4b38dbb6b62bf0d165ac3f96bfd0beac28eddb2e Mon Sep 17 00:00:00 2001 From: zhangyijian Date: Sun, 12 Jul 2026 19:35:04 +0800 Subject: [PATCH 1/2] cleanup example profile code --- examples/finger_pipeline.py | 79 ++----------------------------------- 1 file changed, 4 insertions(+), 75 deletions(-) diff --git a/examples/finger_pipeline.py b/examples/finger_pipeline.py index f359976..b5e04d7 100644 --- a/examples/finger_pipeline.py +++ b/examples/finger_pipeline.py @@ -12,7 +12,6 @@ For the full demo (UV debug panels, dashboard, benchmarks) see: import argparse import os import sys -import time os.environ.setdefault("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0") @@ -20,19 +19,6 @@ import cv2 import orisys from orisys.finger import FingerRuntime -from pipeline.profiling import StageProfiler, run_deformation_timed - -_FINGER_PIPELINE_STAGES = ( - "capture", - "uv_unroll", - "flow", - "hhd", - "contact", - "read_info", - "display", - "total", -) - def main(): parser = argparse.ArgumentParser(description="Minimum UV-unroll finger tactile pipeline") @@ -41,17 +27,6 @@ def main(): parser.add_argument("--config", "-c", default="./config/dd02-ov.json", help="Orisys SDK config") parser.add_argument("--show", action="store_true", default=True, help="Show unrolled image window") parser.add_argument("--verbose", action="store_true", help="SDK verbose logs") - parser.add_argument( - "--profile", - action="store_true", - help="Print per-stage timing (capture, UV, flow, HHD, contact, read_info, display)", - ) - parser.add_argument( - "--profile-every", - type=int, - default=30, - help="When --profile is set, print rolling averages every N frames (default: 30)", - ) args = parser.parse_args() try: @@ -77,48 +52,17 @@ def main(): runtime.warmup(color=False) tactile = runtime.tactile - profiler = ( - StageProfiler(report_every=args.profile_every, stage_order=_FINGER_PIPELINE_STAGES) - if args.profile - else None - ) print("Press 'q' to quit, 'r' to reset tracker.") - if args.profile: - print(f"Profiling enabled (report every {args.profile_every} frames).") try: while True: - frame_t0 = time.perf_counter() + ok, unrolled = runtime.grab_and_process(color=False) + if not ok: + break - if profiler is not None: - t0 = time.perf_counter() - ok, frame = runtime.read_source() - profiler.record("capture", (time.perf_counter() - t0) * 1000.0) - if not ok: - break - t0 = time.perf_counter() - unrolled = runtime.process_frame(frame, color=False) - profiler.record("uv_unroll", (time.perf_counter() - t0) * 1000.0) - else: - ok, unrolled = runtime.grab_and_process(color=False) - if not ok: - break - - if profiler is not None: - flow_ms, hhd_ms = run_deformation_timed( - tactile, check_motion=True, threshold=0 - ) - profiler.record("flow", flow_ms) - profiler.record("hhd", hhd_ms) - else: - tactile.compute_deformation(check_motion=True, threshold=0) - - t0 = time.perf_counter() + tactile.compute_deformation(check_motion=True, threshold=0) tactile.compute_contact() - if profiler is not None: - profiler.record("contact", (time.perf_counter() - t0) * 1000.0) - t0 = time.perf_counter() fps, flow, vnormal, img, contour, centroid, depth_map, fnormal, fshearx, fsheary = tactile.read_info( tactile.info.FPS, tactile.info.VRAW, @@ -131,8 +75,6 @@ def main(): tactile.info.FSHEARX, tactile.info.FSHEARY, ) - if profiler is not None: - profiler.record("read_info", (time.perf_counter() - t0) * 1000.0) status = ( f"FPS={fps:.2f} normal={fnormal:.2f} shear=({fshearx:.2f}, {fsheary:.2f}) " @@ -140,7 +82,6 @@ def main(): ) if args.show: - t0 = time.perf_counter() arrows = orisys.util.draw_arrows( unrolled, flow, @@ -149,17 +90,7 @@ def main(): arrow_scale=1.0, ) cv2.imshow("UV Unrolled", arrows) - if profiler is not None: - profiler.record("display", (time.perf_counter() - t0) * 1000.0) - if profiler is not None: - total_ms = (time.perf_counter() - frame_t0) * 1000.0 - profiler.record("total", total_ms) - status += ( - f" | wall={total_ms:.1f}ms flow={profiler.last.get('flow', 0):.1f}ms" - f" hhd={profiler.last.get('hhd', 0):.1f}ms" - ) - profiler.tick() print(status, end="\r") key = cv2.waitKey(1) & 0xFF @@ -170,8 +101,6 @@ def main(): tactile.reset() print("\nTracker reset.") finally: - if profiler is not None and profiler.frame_count: - profiler.print_report(prefix="[profile final]") runtime.close() cv2.destroyAllWindows() From d58fa1caa2922d1c2eae6b2402a7ece301fa757e Mon Sep 17 00:00:00 2001 From: zhangyijian Date: Sun, 12 Jul 2026 19:54:32 +0800 Subject: [PATCH 2/2] moved examples/app_paths.py into gui --- build/OrisysDashboard.spec | 2 +- build/build_gui_win_pyinstaller.py | 2 +- build/wheel_layout.py | 2 +- examples/README.md | 3 +-- examples/finger_pipeline_3dview.py | 2 +- examples/{ => gui}/app_paths.py | 5 +++-- examples/gui/dashboard.py | 2 +- examples/viz/mesh_camera.py | 2 +- pyproject.toml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) rename examples/{ => gui}/app_paths.py (86%) diff --git a/build/OrisysDashboard.spec b/build/OrisysDashboard.spec index 47bae68..5afc889 100644 --- a/build/OrisysDashboard.spec +++ b/build/OrisysDashboard.spec @@ -6,7 +6,7 @@ a = Analysis( pathex=[], binaries=[], datas=[('D:\\repo\\orisyssdk_git\\config', 'config'), ('D:\\repo\\orisyssdk_git\\assets', 'assets')], - hiddenimports=['PyQt5', 'pyqtgraph', 'open3d', 'cv2', 'orisys', 'gui', 'pipeline', 'viz', 'app_paths', 'plotly', '_plotly_utils', 'open3d.cpu.pybind'], + hiddenimports=['PyQt5', 'pyqtgraph', 'open3d', 'cv2', 'orisys', 'gui', 'pipeline', 'viz', 'gui.app_paths', 'plotly', '_plotly_utils', 'open3d.cpu.pybind'], hookspath=[], hooksconfig={}, runtime_hooks=[], diff --git a/build/build_gui_win_pyinstaller.py b/build/build_gui_win_pyinstaller.py index 9ca0284..b336c1e 100644 --- a/build/build_gui_win_pyinstaller.py +++ b/build/build_gui_win_pyinstaller.py @@ -33,7 +33,7 @@ HIDDEN_IMPORTS = [ "gui", "pipeline", "viz", - "app_paths", + "gui.app_paths", "plotly", "_plotly_utils", # sometimes needed for open3d: diff --git a/build/wheel_layout.py b/build/wheel_layout.py index 00f2ec9..8409458 100644 --- a/build/wheel_layout.py +++ b/build/wheel_layout.py @@ -82,7 +82,7 @@ def copy_bundle_items(repo_root: Path, pkg_dir: Path, items: list[dict]) -> dict def package_data_from_bundle(ext_suffix: str, items: list[dict]) -> dict[str, list[str]]: package_data: dict[str, list[str]] = { "orisys": [f"*{ext_suffix}"], - "orisys.examples": ["*.py", "README.md", "app_paths.py", "viz/**/*.py", "pipeline/**/*.py", "gui/**/*.py"], + "orisys.examples": ["*.py", "README.md", "viz/**/*.py", "pipeline/**/*.py", "gui/**/*.py"], } for item in items: if item["name"] == "examples": diff --git a/examples/README.md b/examples/README.md index 8d5a197..8de1a4d 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,7 +5,6 @@ Top-level demo scripts under `examples/`. Run them from the repository root. ## Top-Level Files - `README.md` — this overview of the root-level example entry points -- `app_paths.py` — path helpers used by the packaged / frozen dashboard entry point - `basic_pipeline.py` — basic single-sensor OpenCV demo for the compound-eye pipeline - `plot_data.py` — single-sensor demo with OpenCV views plus PyQtGraph force charts - `two_sensor_pipeline.py` — two-sensor multiprocessing demo for parallel acquisition / display @@ -59,7 +58,7 @@ pip install -e ".[gui]" ## Notes -- `finger_pipeline_3dview.py` is the main interactive demo. It uses `app_paths.py` so the same entry point works in editable and packaged runs. +- `finger_pipeline_3dview.py` is the main interactive demo. It uses `gui/app_paths.py` so the same entry point works in editable and packaged runs. - Dashboard controls: click **启动** to start acquisition; `Q` quits, `R` resets, `S` starts recording, `E` stops recording, and `Esc` toggles fullscreen. - `finger_pipeline.py` is the leanest finger example if you want to validate UV unroll + force/contact processing without the full dashboard. - `finger_pipeline.py` uses `orisys.finger.FingerRuntime` as the high-level entry point, then runs tactile analysis through `runtime.tactile`. diff --git a/examples/finger_pipeline_3dview.py b/examples/finger_pipeline_3dview.py index 0567d93..ca0362d 100644 --- a/examples/finger_pipeline_3dview.py +++ b/examples/finger_pipeline_3dview.py @@ -15,7 +15,7 @@ import sys os.environ.setdefault("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0") -from app_paths import configure_frozen_runtime, default_config_path, ensure_examples_import_path +from gui.app_paths import configure_frozen_runtime, default_config_path, ensure_examples_import_path configure_frozen_runtime() ensure_examples_import_path() diff --git a/examples/app_paths.py b/examples/gui/app_paths.py similarity index 86% rename from examples/app_paths.py rename to examples/gui/app_paths.py index 3136362..e227e3b 100644 --- a/examples/app_paths.py +++ b/examples/gui/app_paths.py @@ -1,4 +1,4 @@ -"""Resolve bundled resource paths for dev runs and Nuitka standalone builds.""" +"""Resolve bundled resource paths for dev runs and standalone builds.""" from __future__ import annotations @@ -6,7 +6,8 @@ import os import sys from pathlib import Path -_EXAMPLES_DIR = Path(__file__).resolve().parent +_GUI_DIR = Path(__file__).resolve().parent +_EXAMPLES_DIR = _GUI_DIR.parent _REPO_ROOT = _EXAMPLES_DIR.parent diff --git a/examples/gui/dashboard.py b/examples/gui/dashboard.py index 5b79021..a05e0d4 100644 --- a/examples/gui/dashboard.py +++ b/examples/gui/dashboard.py @@ -19,7 +19,7 @@ from PyQt5.QtWidgets import ( from pipeline.config import PipelineConfig from pipeline.service import FingerPipeline -from app_paths import resource_path +from .app_paths import resource_path from .layout import ( DashboardLayout, LAYOUT, diff --git a/examples/viz/mesh_camera.py b/examples/viz/mesh_camera.py index 6dc4f2d..8d05524 100644 --- a/examples/viz/mesh_camera.py +++ b/examples/viz/mesh_camera.py @@ -39,7 +39,7 @@ def resolve_viz_pose_path(path: str | Path | None = None) -> Path: here.parents[2] / raw, ] try: - from app_paths import app_root + from gui.app_paths import app_root candidates.insert(0, app_root() / raw) except ImportError: diff --git a/pyproject.toml b/pyproject.toml index a3a204a..c627639 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ dev_install = true name = "examples" source = "examples" target = "examples" -patterns = ["*.py", "README.md", "app_paths.py", "viz/**/*.py", "pipeline/**/*.py", "gui/**/*.py"] +patterns = ["*.py", "README.md", "viz/**/*.py", "pipeline/**/*.py", "gui/**/*.py"] preserve_tree = true [[tool.orisys.bundle.items]]