diff --git a/example3_plot_data.py b/example3_plot_data.py index ecadbf4..1463545 100644 --- a/example3_plot_data.py +++ b/example3_plot_data.py @@ -4,7 +4,7 @@ import cv2 import orisys import numpy as np import time - +import argparse import pyqtgraph as pg def create_plot(): @@ -90,22 +90,40 @@ for i in range(3): def main(): global start_time - + parser = argparse.ArgumentParser() + parser.add_argument("--video","-v", type=str, default="0", help="Camera ID / Video file path") + parser.add_argument("--config","-c", type=str, default="./config/ddjx01.json", help="Configuration file path") + parser.add_argument("--cal","-cal", type=str, default="./config/ddjx01.npy", help="Calibration file path") + parser.add_argument("--verbose","-verbose", type=bool, default=True, help="Print detailed information") + args = parser.parse_args() + + # 步骤1:创建传感器对象 (必要步骤), + # config_name为配置文件名(内置配置文件名)或路径(自定义配置文件路径) + # cal_path为校准文件路径, 每一个设备需要创建/使用一个校准文件 + + # 方式1: 从视频文件读取 + try: + input = int(args.video) + is_camera = True + sensor = orisys.Sensor(input, config_name=args.config, cal_path= args.cal, verbose=args.verbose) + except: + is_camera = False + sensor = orisys.Sensor(args.video, config_name=args.config, cal_path= args.cal, verbose=args.verbose) # 打开视频 # sensor1 = Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True) # 方式1: 从视频文件读取 - sensor1 = orisys.Sensor(8, config_name="./config/ddjx01.json", cal_path= "./config/ddjx01.npy", cuda=False, verbose=True) + # sensor1 = orisys.Sensor("./s1.mp4", config_name="./config/ddjx01.json", cal_path= "./config/ddjx01.npy", cuda=False, verbose=True) start_time = time.time() is_save = False frame_count = 0 writer = None while True: - sensor1.get_img() # 提取并拼接复眼图像 + sensor.get_img() # 提取并拼接复眼图像 - if is_save and writer is not None and sensor1.frame is not None: + if is_save and writer is not None and sensor.frame is not None: frame_count += 1 - save_img = sensor1.frame + save_img = sensor.frame # Convert grayscale (1 channel) to BGR (3 channels) if needed if len(save_img.shape) == 2 or (len(save_img.shape) == 3 and save_img.shape[2] == 1): @@ -115,15 +133,15 @@ def main(): writer.write(save_img) - sensor1.compute_deformation(check_motion=False) # 计算形变和分解 + sensor.compute_deformation(check_motion=False) # 计算形变和分解 # 提取信息: # 向量场: VRAW, VNORMAL, VSHEAR: 原始,法向,切向 # 帧率,时间戳: FPS, TIMESTAMP # 变形量总和: FNORMAL , FSHEARX, FSHEARY : 法向,切向(X),切向(Y) - fps, fn, fx, fy, flow = sensor1.read_info(sensor1.info.FPS, sensor1.info.FNORMAL, sensor1.info.FSHEARX, sensor1.info.FSHEARY, sensor1.info.VRAW) + fps, fn, fx, fy, flow, vnormal, vshear = sensor.read_info(sensor.info.FPS, sensor.info.FNORMAL, sensor.info.FSHEARX, sensor.info.FSHEARY, sensor.info.VRAW, sensor.info.VNORMAL,sensor.info.VSHEAR) print(fps,fn,fx,fy) # 显示向量场 - arrows = orisys.util.draw_arrows(sensor1.img, flow, threshold=5, grid_spacing=10, arrow_scale=1.0) + arrows = orisys.util.draw_arrows(sensor.img, flow, threshold=5, grid_spacing=10, arrow_scale=1.0) cv2.imshow("Deformation", arrows) # 显示深度图 mag = draw_magnitude_map(flow) @@ -149,7 +167,7 @@ def main(): # Ensure directory exists os.makedirs(os.path.dirname(save_path), exist_ok=True) # Get frame dimensions from the actual frame - save_img = sensor1.frame + save_img = sensor.frame if save_img is not None: # Convert grayscale (1 channel) to BGR (3 channels) if needed for dimension check @@ -180,7 +198,7 @@ def main(): print(f"Stop writing, total frames: {frame_count}") frame_count = 0 - sensor1.disconnect() # 断开传感器连接 + sensor.disconnect() # 断开传感器连接 diff --git a/src/orisys/sensor.py b/src/orisys/sensor.py index 86a08d0..04fc6d6 100644 --- a/src/orisys/sensor.py +++ b/src/orisys/sensor.py @@ -151,9 +151,12 @@ class Sensor: self.__tracker = Tracker(adaptive=True, cuda=cuda, verbose=self.verbose, config_tracker=self.__config_tracker) self.__contact3d = Contact3D(config_contact=self.__config_contact, verbose=self.verbose) self.__hhd = None - # cfg_ds = self.__config_tracker.get("hhd_downsample", None) - # self._hhd_downsample = max(1, int(cfg_ds if cfg_ds is not None else hhd_downsample)) - self._hhd_downsample = self.__config_tracker.get("hhd_downsample", None) + # Integer >= 1: run HHD on flow downsampled by this factor for speed (1 = full res). + _raw_ds = self.__config_tracker.get("hhd_downsample", 1) + try: + self._hhd_downsample = max(1, int(_raw_ds)) if _raw_ds is not None else 1 + except (TypeError, ValueError): + self._hhd_downsample = 1 self._hhd_grid_shape = None cfg_backend = self.__config_tracker.get("backend", None) self.poisson_backend = cfg_backend if cfg_backend is not None else backend @@ -300,7 +303,10 @@ class Sensor: raise Exception("Warning: Compute flow first") orig_h, orig_w = flow.shape[:2] - k = self._hhd_downsample + try: + k = max(1, int(self._hhd_downsample)) + except (TypeError, ValueError): + k = 1 if k > 1: ds_w = max(1, orig_w // k)