From fbffe0088f3505e0623cee1af2a2eee4dfa05b9b Mon Sep 17 00:00:00 2001 From: bluepulsar Date: Wed, 31 Dec 2025 19:37:33 +0800 Subject: [PATCH] test --- example1_basic_pipeline.py | 4 ++-- example2_async_pipeline.py | 3 ++- example3_two_sensor_pipeline.py | 8 ++++--- src/orisys/MultiSensor.py | 8 +++---- src/orisys/configs/__init__.py | 11 ++++++++++ src/orisys/sensor.py | 39 +++++++++++++++++---------------- 6 files changed, 44 insertions(+), 29 deletions(-) diff --git a/example1_basic_pipeline.py b/example1_basic_pipeline.py index a9d5378..53e17ee 100644 --- a/example1_basic_pipeline.py +++ b/example1_basic_pipeline.py @@ -19,10 +19,10 @@ def main(): # 步骤1:创建传感器对象 (必要步骤),config_name为配置文件名(内置配置文件名)或路径(自定义配置文件路径) # 方式1: 从视频文件读取 - # sensor = orisys.Sensor("./s1.mp4", isstitch=True, cuda=True, verbose=True,config_name="prototype") + sensor = orisys.Sensor("./s1.mp4", isstitch=True, cuda=True, verbose=True,config_name="prototype") # 方式2: 从摄像头读取(取消注释使用) - sensor = orisys.Sensor(0, cuda=True, verbose=True, config_name="prototype") + # sensor = orisys.Sensor(0, cuda=True, verbose=True, config_name="prototype") sensor.export_config(path="./config/exported_config.json") # 导出配置文件供查看和修改 print("\n按 'q' 退出程序,按 'r' 重置光流追踪器") diff --git a/example2_async_pipeline.py b/example2_async_pipeline.py index e557980..9dfa9c3 100644 --- a/example2_async_pipeline.py +++ b/example2_async_pipeline.py @@ -37,7 +37,8 @@ def main(): # ========================================================================= # 1. 初始化传感器 # ========================================================================= - sensor = orisys.Sensor(0, cuda=True, verbose=True, config_name="prototype") + # sensor = orisys.Sensor(0, cuda=True, verbose=True, config_name="prototype") + sensor = orisys.Sensor("./s1.mp4", isstitch=True, cuda=True, verbose=True,config_name="prototype") # ========================================================================= # 2. 启用异步流水线 diff --git a/example3_two_sensor_pipeline.py b/example3_two_sensor_pipeline.py index c25a0bb..a434d64 100644 --- a/example3_two_sensor_pipeline.py +++ b/example3_two_sensor_pipeline.py @@ -43,14 +43,16 @@ def main(): 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy', - 'config_name': "prototype" + 'config_name': "prototype", + 'compute_contact': True }, { 'vid_src': './s1.mp4', 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy', - 'config_name': "prototype" + 'config_name': "prototype", + 'compute_contact': True }, ] @@ -63,7 +65,7 @@ def main(): # - 持续采集和处理数据 # - 通过队列将结果传回主进程 # compute_contact=True 启用接触点检测(深度图、质心、轮廓) - with orisys.MultiSensor(configs, compute_contact=True) as multi: + with orisys.MultiSensor(configs) as multi: print("\n多传感器已启动,按 'q' 退出") # ===================================================================== diff --git a/src/orisys/MultiSensor.py b/src/orisys/MultiSensor.py index 8fb8c77..4f0ae2d 100644 --- a/src/orisys/MultiSensor.py +++ b/src/orisys/MultiSensor.py @@ -9,7 +9,7 @@ independent CUDA contexts. import os -def _sensor_worker(sensor_id, config, data_queue, stop_event, compute_contact=False): +def _sensor_worker(sensor_id, config, data_queue, stop_event): """ Worker function that runs in a separate PROCESS for each sensor. Each process has its own Python interpreter and CUDA context. @@ -28,6 +28,7 @@ def _sensor_worker(sensor_id, config, data_queue, stop_event, compute_contact=Fa config_name=config.get('config_name', 'prototype'), cal_path=config.get('cal_path', None) ) + compute_contact = config.get('compute_contact', False) frame_count = 0 @@ -156,7 +157,7 @@ class MultiSensor: multi.stop() """ - def __init__(self, sensor_configs, compute_contact=False): + def __init__(self, sensor_configs): """ Initialize MultiSensor manager. @@ -181,7 +182,6 @@ class MultiSensor: self.sensor_configs = sensor_configs self.num_sensors = len(sensor_configs) self._mp = mp - self.compute_contact = compute_contact self.processes = [] self.data_queues = [] @@ -202,7 +202,7 @@ class MultiSensor: for i, config in enumerate(self.sensor_configs): process = self._mp.Process( target=_sensor_worker, - args=(i, config, self.data_queues[i], self.stop_events[i], self.compute_contact), + args=(i, config, self.data_queues[i], self.stop_events[i]), daemon=True ) process.start() diff --git a/src/orisys/configs/__init__.py b/src/orisys/configs/__init__.py index e5f05f7..b4f5381 100644 --- a/src/orisys/configs/__init__.py +++ b/src/orisys/configs/__init__.py @@ -56,6 +56,17 @@ def load_config(config_name_or_path): with open(package_config_path, 'r', encoding='utf-8') as f: return json.load(f) +def list_configs(): + """ + List all available JSON configuration files in the configs directory. + + Returns: + List of configuration names (without .json extension), sorted alphabetically. + Returns an empty list if no JSON files are found. + """ + config_files = sorted(CONFIG_DIR.glob("*.json")) + return [f.stem for f in config_files] + def _format_json_value(value, indent_level=0, indent_str=" "): """ Recursively format JSON value with arrays/lists on single line. diff --git a/src/orisys/sensor.py b/src/orisys/sensor.py index 8cf3fa6..e7f9d9a 100644 --- a/src/orisys/sensor.py +++ b/src/orisys/sensor.py @@ -296,21 +296,21 @@ class Sensor: # return getFilteredDensity(self.vnormal, use_cuda=self.cuda) # self.depth = getFilteredDensity(self.vnormal, use_cuda=self.cuda) - def update(self): - """ - Convenience method: get_img + compute_deformation in one call. + # def update(self): + # """ + # Convenience method: get_img + compute_deformation in one call. - Returns: - dict: All sensor data - """ - self.get_img() - self.compute_deformation() - return { - 'img': self.__img, 'flow': self.__flow, - 'normal': self.__vnormal, 'shear': self.__vshear, 'depth': self.__depth_map, - 'fps': self._fps, 'fnormal': self.__fnormal, - 'fshearx': self.__fshearx, 'fsheary': self.__fsheary, 'ftor': self.__ftor, - } + # Returns: + # dict: All sensor data + # """ + # self.get_img() + # self.compute_deformation() + # return { + # 'img': self.__img, 'flow': self.__flow, + # 'normal': self.__vnormal, 'shear': self.__vshear, 'depth': self.__depth_map, + # 'fps': self._fps, 'fnormal': self.__fnormal, + # 'fshearx': self.__fshearx, 'fsheary': self.__fsheary, 'ftor': self.__ftor, + # } def read_info(self, *args) -> Tuple: """ @@ -478,16 +478,19 @@ class Sensor: self.cal_path = "./config/cal.npy" if os.path.exists(self.cal_path): - print("Loading calibration from", self.cal_path) + if self.verbose: + print("Loading calibration from", self.cal_path) self.stitch_calibration = np.load(self.cal_path, allow_pickle=True) self.__stitcher.stitch_calibration = self.stitch_calibration return self.__stitcher.stitch_rt_optimized() else: - print("Creating new calibration...") + if self.verbose: + print("Creating new calibration...") img, self.stitch_calibration = self.__stitcher.stitch_cal() os.makedirs("./config", exist_ok=True) np.save(self.cal_path, self.stitch_calibration) - print("Calibration saved to", self.cal_path) + if self.verbose: + print("Calibration saved to", self.cal_path) return img # ========================================================================= @@ -508,8 +511,6 @@ class Sensor: if self.verbose: print(f"Config: {self.config_name}") - print(f" Resolution: {self._config_resolution_raw} → {self._config_resolution_stitch}") - print(f" FPS: {self._config_fps}, Units: {self._config_units}") return True def _open_video_source(self, override, box):