improve readme.md and configs util functions

This commit is contained in:
bluepulsar
2026-01-04 12:52:08 +08:00
parent 1baa0fb954
commit 807785ca7f
6 changed files with 191 additions and 38 deletions
+6 -1
View File
@@ -11,5 +11,10 @@ __author__ = "Orisys"
from .sensor import Sensor
from .MultiSensor import MultiSensor
from . import util
from . import configs
__all__ = ['Sensor', 'MultiSensor', 'util']
# Re-export list_configs as list_config for convenience
list_config = configs.list_config
export_config = configs.export_config
__all__ = ['Sensor', 'MultiSensor', 'util', 'list_config', 'export_config']
+4 -2
View File
@@ -56,7 +56,7 @@ 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():
def list_config():
"""
List all available JSON configuration files in the configs directory.
@@ -98,7 +98,7 @@ def _format_json_value(value, indent_level=0, indent_str=" "):
# Primitive types (string, number, bool, None)
return json.dumps(value, ensure_ascii=False)
def export_config(config, path="./config/exported_config.json"):
def export_config(config_name = None, path="./config/exported_config.json"):
"""
Export configuration to JSON file with readable formatting.
Arrays/lists are kept on a single line, while nested objects are indented.
@@ -110,6 +110,7 @@ def export_config(config, path="./config/exported_config.json"):
Returns:
The exported config dictionary
"""
config = load_config(config_name)
Path(path).parent.mkdir(parents=True, exist_ok=True)
with open(path, 'w', encoding='utf-8') as f:
@@ -117,5 +118,6 @@ def export_config(config, path="./config/exported_config.json"):
f.write(formatted)
f.write('\n') # Add trailing newline
print(f"Config name: {config_name} exported to {path}")
return config
+9 -9
View File
@@ -21,7 +21,6 @@ from .nHHD import nHHD
from . import configs
from .get_depth import Contact3D
class Sensor:
"""
Optical tactile sensor interface with deformation analysis.
@@ -200,7 +199,7 @@ class Sensor:
if self.mirror:
self.__img = cv2.flip(self.__img, 1)
return True
return self.__img.copy()
def compute_deformation(self):
"""
@@ -228,7 +227,6 @@ class Sensor:
if hasattr(flow, 'download'):
flow = flow.download()
self.__flow = flow
return True
def __compute_hhd(self):
@@ -358,12 +356,14 @@ class Sensor:
# Public API - Configuration & Calibration
# =========================================================================
def export_config(self, path="./config/exported_config.json"):
"""Return current configuration dict."""
configs.export_config(self._config, path)
if self.verbose:
print(f"Config exported to {path}")
return True
# def export_config(self, path="./config/exported_config.json"):
# """Return current configuration dict."""
# configs.export_config(self._config, path)
# if self.verbose:
# print(f"Config exported to {path}")
# return True
def stitch_cal(self):
"""