From 6a0c3f16ea02bc7f17d20e882edd2c1aef621278 Mon Sep 17 00:00:00 2001 From: radxa-d6a Date: Wed, 18 Feb 2026 21:28:32 +0800 Subject: [PATCH] expose flow and hhd for benchmark --- benchmark.py | 18 +++++++++++++----- src/orisys/HHD.py | 4 ++-- src/orisys/sensor.py | 8 ++++---- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/benchmark.py b/benchmark.py index ebe8d5b..5b11e61 100644 --- a/benchmark.py +++ b/benchmark.py @@ -20,7 +20,7 @@ def main(): # cal_path为校准文件路径, 每一个设备需要创建/使用一个校准文件 # 方式1: 从视频文件读取 - sensor = orisys.Sensor("s1.mp4", config_name="./config/prototype_of3.json", cal_path= "./config/dd01a_0.npy", isstitch=True, cuda=False, verbose=True, poisson_backend='opencl') + sensor = orisys.Sensor("s1_480p.mp4", config_name="./config/prototype_of3_480p.json", cal_path= "./config/dd01a_0_480p.npy", isstitch=True, cuda=False, verbose=True, poisson_backend='cpu') # 方式2: 从摄像头读取(取消注释使用) # sensor = orisys.Sensor(0, config_name="./config/prototype_of3.json", cal_path= "./config/cal.npy", isstitch=True, cuda=True, verbose=True) @@ -39,9 +39,17 @@ def main(): # print("motion detected") # 步骤 2.2: 计算形变场 (必要步骤) start_time = time.perf_counter() - sensor.compute_deformation() + sensor.compute_flow() + end_time = time.perf_counter() - compute_deformation_time = end_time - start_time + compute_flow_time = end_time - start_time + + start_time = time.perf_counter() + sensor.compute_hhd() + + end_time = time.perf_counter() + compute_hhd_time = end_time - start_time + # 步骤 2.3: 计算触碰点 start_time = time.perf_counter() sensor.compute_contact() @@ -98,8 +106,8 @@ def main(): capture_time = sensor._last_capture_time processing_time = sensor._last_processing_time - total_time = get_img_time + compute_deformation_time + compute_contact_time + read_info_time + display_time - print(f"get_img: {get_img_time*1000:.2f}ms (capture: {capture_time*1000:.2f}ms, processing: {processing_time*1000:.2f}ms), deformation: {compute_deformation_time*1000:.2f}ms, contact: {compute_contact_time*1000:.2f}ms, read: {read_info_time*1000:.2f}ms, display: {display_time*1000:.2f}ms, total: {total_time*1000:.2f}ms") + total_time = get_img_time + compute_flow_time + compute_hhd_time + compute_contact_time + read_info_time + display_time + print(f"get_img: {get_img_time*1000:.2f}ms (capture: {capture_time*1000:.2f}ms, processing: {processing_time*1000:.2f}ms), flow: {compute_flow_time*1000:.2f}ms,hhd: {compute_hhd_time*1000:.2f}ms, contact: {compute_contact_time*1000:.2f}ms, read: {read_info_time*1000:.2f}ms, display: {display_time*1000:.2f}ms, total: {total_time*1000:.2f}ms") #步骤 3.5: 键盘控制 key = cv2.waitKey(1) & 0xFF diff --git a/src/orisys/HHD.py b/src/orisys/HHD.py index cf44110..819850f 100644 --- a/src/orisys/HHD.py +++ b/src/orisys/HHD.py @@ -1628,7 +1628,7 @@ class PoissonSolver(object): Batched OpenCL Poisson solver for two 2D fields. Optimized: scatter H2D (~4x smaller transfer), fused multiply (reads g_fft once), async D2H (one sync instead of two). - When profile=True, records and optionally prints per-stage timings. + When profile=False, records and optionally prints per-stage timings. """ if not OPENCL_AVAILABLE: if verbose: @@ -1818,7 +1818,7 @@ class PoissonSolver(object): # """ # OpenCL Poisson solver using pyvkfft FFT convolution. # Replaces scipy.signal.fftconvolve(..., mode='same') for structured grids. - # When profile=True, records and optionally prints per-stage timings. + # When profile=False, records and optionally prints per-stage timings. # """ # if not OPENCL_AVAILABLE: # if verbose: diff --git a/src/orisys/sensor.py b/src/orisys/sensor.py index 4206e29..a0561a6 100644 --- a/src/orisys/sensor.py +++ b/src/orisys/sensor.py @@ -210,13 +210,13 @@ class Sensor: if self.img is None: raise Exception("Warning: Get image first") - self.__compute_flow() + self.compute_flow() if decompose: - self.__compute_hhd() + self.compute_hhd() return True - def __compute_flow(self): + def compute_flow(self): if self.img is None: raise Exception("Warning: Get image first") @@ -226,7 +226,7 @@ class Sensor: flow = flow.download() self.flow = flow - def __compute_hhd(self): + def compute_hhd(self): flow = self.flow if flow is None: