cleanup example profile code
This commit is contained in:
@@ -12,7 +12,6 @@ For the full demo (UV debug panels, dashboard, benchmarks) see:
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
|
|
||||||
os.environ.setdefault("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0")
|
os.environ.setdefault("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0")
|
||||||
|
|
||||||
@@ -20,19 +19,6 @@ import cv2
|
|||||||
import orisys
|
import orisys
|
||||||
from orisys.finger import FingerRuntime
|
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():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Minimum UV-unroll finger tactile pipeline")
|
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("--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("--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("--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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -77,48 +52,17 @@ def main():
|
|||||||
|
|
||||||
runtime.warmup(color=False)
|
runtime.warmup(color=False)
|
||||||
tactile = runtime.tactile
|
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.")
|
print("Press 'q' to quit, 'r' to reset tracker.")
|
||||||
if args.profile:
|
|
||||||
print(f"Profiling enabled (report every {args.profile_every} frames).")
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
frame_t0 = time.perf_counter()
|
|
||||||
|
|
||||||
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)
|
ok, unrolled = runtime.grab_and_process(color=False)
|
||||||
if not ok:
|
if not ok:
|
||||||
break
|
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)
|
tactile.compute_deformation(check_motion=True, threshold=0)
|
||||||
|
|
||||||
t0 = time.perf_counter()
|
|
||||||
tactile.compute_contact()
|
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(
|
fps, flow, vnormal, img, contour, centroid, depth_map, fnormal, fshearx, fsheary = tactile.read_info(
|
||||||
tactile.info.FPS,
|
tactile.info.FPS,
|
||||||
tactile.info.VRAW,
|
tactile.info.VRAW,
|
||||||
@@ -131,8 +75,6 @@ def main():
|
|||||||
tactile.info.FSHEARX,
|
tactile.info.FSHEARX,
|
||||||
tactile.info.FSHEARY,
|
tactile.info.FSHEARY,
|
||||||
)
|
)
|
||||||
if profiler is not None:
|
|
||||||
profiler.record("read_info", (time.perf_counter() - t0) * 1000.0)
|
|
||||||
|
|
||||||
status = (
|
status = (
|
||||||
f"FPS={fps:.2f} normal={fnormal:.2f} shear=({fshearx:.2f}, {fsheary:.2f}) "
|
f"FPS={fps:.2f} normal={fnormal:.2f} shear=({fshearx:.2f}, {fsheary:.2f}) "
|
||||||
@@ -140,7 +82,6 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
if args.show:
|
if args.show:
|
||||||
t0 = time.perf_counter()
|
|
||||||
arrows = orisys.util.draw_arrows(
|
arrows = orisys.util.draw_arrows(
|
||||||
unrolled,
|
unrolled,
|
||||||
flow,
|
flow,
|
||||||
@@ -149,17 +90,7 @@ def main():
|
|||||||
arrow_scale=1.0,
|
arrow_scale=1.0,
|
||||||
)
|
)
|
||||||
cv2.imshow("UV Unrolled", arrows)
|
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")
|
print(status, end="\r")
|
||||||
|
|
||||||
key = cv2.waitKey(1) & 0xFF
|
key = cv2.waitKey(1) & 0xFF
|
||||||
@@ -170,8 +101,6 @@ def main():
|
|||||||
tactile.reset()
|
tactile.reset()
|
||||||
print("\nTracker reset.")
|
print("\nTracker reset.")
|
||||||
finally:
|
finally:
|
||||||
if profiler is not None and profiler.frame_count:
|
|
||||||
profiler.print_report(prefix="[profile final]")
|
|
||||||
runtime.close()
|
runtime.close()
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user