diff --git a/config/compound_eye.png b/config/compound_eye.png index cf07b80..ef3b17b 100644 Binary files a/config/compound_eye.png and b/config/compound_eye.png differ diff --git a/example1_basic.py b/example1_basic.py index 5cc1533..c00d22e 100644 --- a/example1_basic.py +++ b/example1_basic.py @@ -10,6 +10,7 @@ def main(): # 打开视频 sensor1 = Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True) + # 打开摄像头 # sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True) while True: diff --git a/example2_config.py b/example2_config.py new file mode 100644 index 0000000..76971ea --- /dev/null +++ b/example2_config.py @@ -0,0 +1,46 @@ +import os +os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0" +import cv2 +from orisys import Sensor +import numpy as np + + +def main(): + global start_time + + # 打开视频 + sensor1 = Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True) + config = sensor1.get_config() + print(config) + + # 打开摄像头 + # sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True) + while True: + sensor1.get_img() # 提取并拼接复眼图像 + sensor1.compute_deformation() # 计算形变和分解 + # 提取信息: + # 向量场: VRAW, VNORMAL, VSHEAR: 原始,法向,切向 + # 帧率,时间戳: FPS, TIMESTAMP + # 变形量总和: FNORMAL , FSHEARX, FSHEARY : 法向,切向(X),切向(Y) + # 深度图: DEPTH + fps, fn, fx, fy, flow, depth = sensor1.read_info(sensor1.info.FPS, sensor1.info.FNORMAL, sensor1.info.FSHEARX, sensor1.info.FSHEARY, sensor1.info.VRAW, sensor1.info.DEPTH) + print(fps,fn,fx,fy) + # 显示向量场 + arrows = sensor1.draw_arrows(sensor1.info.VRAW, threshold=5, grid_spacing=40, arrow_scale=1.0) + cv2.imshow("Deformation", arrows) + + depth_img = cv2.applyColorMap((depth*1* 255.0).astype('uint8'), cv2.COLORMAP_HOT) + + cv2.imshow('depth', depth_img) + + key = cv2.waitKey(1) + if key & 0xFF == ord("q"): + print("\n 停止程序") + break + + sensor1.disconnect() # 断开传感器连接 + + + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index b4c8593..5a4c163 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,11 @@ from setuptools import setup, find_packages +from pathlib import Path + +# Find all JSON files in the configs directory +configs_dir = Path("src/orisys/configs") +json_files = [] +if configs_dir.exists(): + json_files = [str(p.relative_to("src")) for p in configs_dir.glob("*.json")] setup( name="orisys", @@ -7,6 +14,10 @@ setup( author="Your Name", package_dir={"": "src"}, packages=find_packages(where="src"), + package_data={ + "orisys": ["configs/*.json"], + }, + include_package_data=True, install_requires=[ "numpy", "opencv-python", diff --git a/src/orisys/configs/__init__.py b/src/orisys/configs/__init__.py index aa0ffb9..118737a 100644 --- a/src/orisys/configs/__init__.py +++ b/src/orisys/configs/__init__.py @@ -4,11 +4,44 @@ from pathlib import Path CONFIG_DIR = Path(__file__).parent def load_config(config_name: str): + """ + Load sensor configuration from JSON file. + + Args: + config_name: Name of the config file (without .json extension) + + Returns: + Dictionary containing the configuration + + Raises: + FileNotFoundError: If the config file doesn't exist + """ config_path = CONFIG_DIR / f"{config_name}.json" + + if not config_path.exists(): + # List available configs for better error message + available = [f.stem for f in CONFIG_DIR.glob("*.json")] + available_str = ", ".join(available) if available else "none" + raise FileNotFoundError( + f"Config file not found: {config_path}\n" + f"Available configs: {available_str}" + ) + with open(config_path, 'r') as f: return json.load(f) def save_config(config: dict, config_name: str): + """ + Save sensor configuration to JSON file. + + Args: + config: Dictionary containing the configuration + config_name: Name of the config file (without .json extension) + + Returns: + Path to the saved config file + """ config_path = CONFIG_DIR / f"{config_name}.json" with open(config_path, 'w') as f: - json.dump(config, f, indent=4) \ No newline at end of file + json.dump(config, f, indent=4) + return config_path \ No newline at end of file diff --git a/src/orisys/configs/prototpye.json b/src/orisys/configs/prototype.json similarity index 52% rename from src/orisys/configs/prototpye.json rename to src/orisys/configs/prototype.json index 99f24ef..0ac9dc8 100644 --- a/src/orisys/configs/prototpye.json +++ b/src/orisys/configs/prototype.json @@ -5,19 +5,20 @@ "resolution_raw": [1920, 1080], "fps": 60, "units": 15, - "resolution_stitch": [400, 400] + "resolution_stitch": [400, 400], + "index": [1,2,3,6,7,8,11,12,13], + "pos_default": [[260, 56], [577, 62], [897, 69], [1214, 75], [1530, 81], [256, 391], [570, 397], [889, 403], [1208, 409], [1523, 416], [248, 724], [563, 730], [882, 738], [1201, 743], [1516, 751]] }, "elastomer": { "thickness_mm": 3.0, "marker_pattern": "random_color", "marker_version": "1.0" }, - "mechanical":{ + "mechanical": { "width_mm": 10, "height_mm": 10, "depth_mm": 10 - } - } - - \ No newline at end of file +} + + diff --git a/src/orisys/sensor.py b/src/orisys/sensor.py index feb2ce5..5457263 100644 --- a/src/orisys/sensor.py +++ b/src/orisys/sensor.py @@ -13,13 +13,14 @@ from scipy.interpolate import griddata from enum import Enum, auto from typing import Optional, Tuple, Union, Any from .getDensity import getFilteredDensity +from . import configs class Sensor: """ Sensor helper that can decompose optical flow via Fourier methods. Stores the decomposed components and global norms as attributes after compute(). """ - def __init__(self, vid_src, isstitch=False, verbose=True, cuda=True): + def __init__(self, vid_src, isstitch=False, verbose=True, cuda=True, config_name="prototype"): """ Initialize Sensor with video source and configuration. @@ -110,6 +111,8 @@ class Sensor: FSHEARY = auto() DEPTH = auto() + def get_config(self): + return configs.load_config("prototype") def get_img(self): """