json works

This commit is contained in:
bluepulsar
2025-12-25 15:23:17 +08:00
parent 64f07fdfb9
commit 038941593e
7 changed files with 103 additions and 8 deletions
+34 -1
View File
@@ -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)
json.dump(config, f, indent=4)
return config_path
@@ -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
}
}
}
+4 -1
View File
@@ -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):
"""