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
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.0 MiB

+1
View File
@@ -10,6 +10,7 @@ def main():
# 打开视频 # 打开视频
sensor1 = Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True) sensor1 = Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True)
# 打开摄像头 # 打开摄像头
# sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True) # sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True)
while True: while True:
+46
View File
@@ -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()
+11
View File
@@ -1,4 +1,11 @@
from setuptools import setup, find_packages 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( setup(
name="orisys", name="orisys",
@@ -7,6 +14,10 @@ setup(
author="Your Name", author="Your Name",
package_dir={"": "src"}, package_dir={"": "src"},
packages=find_packages(where="src"), packages=find_packages(where="src"),
package_data={
"orisys": ["configs/*.json"],
},
include_package_data=True,
install_requires=[ install_requires=[
"numpy", "numpy",
"opencv-python", "opencv-python",
+34 -1
View File
@@ -4,11 +4,44 @@ from pathlib import Path
CONFIG_DIR = Path(__file__).parent CONFIG_DIR = Path(__file__).parent
def load_config(config_name: str): 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" 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: with open(config_path, 'r') as f:
return json.load(f) return json.load(f)
def save_config(config: dict, config_name: str): 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" config_path = CONFIG_DIR / f"{config_name}.json"
with open(config_path, 'w') as f: 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], "resolution_raw": [1920, 1080],
"fps": 60, "fps": 60,
"units": 15, "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": { "elastomer": {
"thickness_mm": 3.0, "thickness_mm": 3.0,
"marker_pattern": "random_color", "marker_pattern": "random_color",
"marker_version": "1.0" "marker_version": "1.0"
}, },
"mechanical":{ "mechanical": {
"width_mm": 10, "width_mm": 10,
"height_mm": 10, "height_mm": 10,
"depth_mm": 10 "depth_mm": 10
} }
} }
+4 -1
View File
@@ -13,13 +13,14 @@ from scipy.interpolate import griddata
from enum import Enum, auto from enum import Enum, auto
from typing import Optional, Tuple, Union, Any from typing import Optional, Tuple, Union, Any
from .getDensity import getFilteredDensity from .getDensity import getFilteredDensity
from . import configs
class Sensor: class Sensor:
""" """
Sensor helper that can decompose optical flow via Fourier methods. Sensor helper that can decompose optical flow via Fourier methods.
Stores the decomposed components and global norms as attributes after compute(). 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. Initialize Sensor with video source and configuration.
@@ -110,6 +111,8 @@ class Sensor:
FSHEARY = auto() FSHEARY = auto()
DEPTH = auto() DEPTH = auto()
def get_config(self):
return configs.load_config("prototype")
def get_img(self): def get_img(self):
""" """