diff --git a/Readme.md b/Readme.md index 63b40b3..dbda6df 100644 --- a/Readme.md +++ b/Readme.md @@ -1,13 +1,54 @@ # orisys API 文档 本文件提供了 `orisys` 套件的中文文档 -## 使用方法 -1. 根据平台和python 版本下载对应的`.whl`文件 + +## 准备 Python 开发环境 +推荐下载 Anaconda,并使用Python 3.10 +``` +# 创建并激活虚拟环境 +conda create -n orisys python=3.10 +conda activate orisys +``` +## 安装 CUDA Toolkit 和 cuDNN +在官方链接下载和安装:https://developer.nvidia.com/cuda/toolkit +或 +在Anaconda环境中安装(例子使用cuda12.9): +https://anaconda.org/channels/nvidia/packages/cuda/overview +``` +conda install nvidia/label/cuda-12.9.0::cuda-toolkit nvidia::cudnn +``` +## SDK安装方法 +1. 根据平台(win / linux)和python (如p38、p39、p310)版本下载对应的`.whl`文件 2. 运行pip命令安装: ```bash -pip install orisys-{version}-{python-version}-none-{os}_amd64.whl +pip install orisys-{version}-{python-version}-{python-version}-{os}_amd64.whl ``` -3. 并测试导入: +如 +```bash +pip install orisys-0.2.0-cp310-cp310-win_amd64.whl +``` + +3. **安装 CuPy(根据您的 CUDA 版本选择):** + + **方法 1:使用 extras(推荐)** + ```bash + # 对于 CUDA 12.x + pip install orisys[cuda12] + + # 对于 CUDA 13.x + pip install orisys[cuda13] + ``` + + **方法 2:手动安装** + ```bash + # 对于 CUDA 12.x + pip install cupy-cuda12x>=12.3.0 + + # 对于 CUDA 13.x + pip install cupy-cuda13x>=13.0.0 + ``` + +4. 测试导入: ```python import orisys print(orisys.__version__) @@ -21,8 +62,8 @@ print(orisys.__version__) * **isstitch** (`bool`,可选): 是否启用图像拼接,默认为 `True`。 * **cuda** (`bool`,可选): 是否使用 GPU cuda 加速,默认为 `False`。 * **verbose** (`bool`,可选): 是否输出初始化及运行过程中的详细日志信息,默认为 `False`。 -* **config_name** (`str`,可选): 内部算法或传感器配置名称,用于加载对应的参数配置,默认为 `prototype`。 - +* **config_name** (`str`,可选): 内部算法或传感器配置`json`文件路径,用于加载对应的参数配置,默认为 `prototype`。 +* **cal_path** (`str`,可选): 复眼拼接校准文件路径,默认为 `./config/cal.npy`。有多个传感器同时运行时建议传感器类创建时建议填写,避免校准文件覆写。在首次运行时程序会在找不到文件时自动创建。 ### 返回 * `Sensor` 实例,用于后续图像采集、形变计算和数据读取操作。 diff --git a/build_nuitka.py b/build_nuitka.py index fca9ee4..9e9cea8 100644 --- a/build_nuitka.py +++ b/build_nuitka.py @@ -86,6 +86,30 @@ def build(): json_count += 1 print(f"Copied {json_count} JSON config files") + # Create and copy examples folder (as part of the package) + examples_dst = pkg_dir / "examples" + examples_dst.mkdir(exist_ok=True) + + # Create __init__.py for examples package + examples_init = examples_dst / "__init__.py" + with open(examples_init, 'w') as f: + f.write("# Examples for orisys package\n") + + example_files = [ + Path("example1_basic_pipeline.py"), + Path("example2_two_sensor_pipeline.py"), + ] + + example_count = 0 + for example_file in example_files: + if example_file.exists(): + shutil.copy(example_file, examples_dst) + example_count += 1 + print(f"Copied example: {example_file.name}") + else: + print(f"Warning: Example file not found: {example_file}") + print(f"Copied {example_count} example files to orisys/examples/") + # Create setup.py for packaging setup_py_path = dist_dir / "setup.py" setup_content = f""" @@ -100,12 +124,24 @@ setup( version="{version}", description="Orisys - Optical Tactile Sensor SDK (Nuitka Compiled)", author="Orisys", - packages=['orisys'], + packages=['orisys', 'orisys.examples'], package_dir={{'': 'wheel_root'}}, package_data={{ 'orisys': ['*.pyd', 'configs/*.json'], + 'orisys.examples': ['*.py'], }}, include_package_data=True, + install_requires=[ + "numpy>=1.24.4", + "opencv-python>=4.10.0.84", + "opencv-contrib-python", + "scipy>=1.10.1", + ], + extras_require={{ + "cuda12": ["cupy-cuda12x>=12.3.0"], + "cuda13": ["cupy-cuda13x>=13.0.0"], + "cuda": ["cupy-cuda12x>=12.3.0"], # For backward compatibility, defaults to CUDA 12.x + }}, distclass=BinaryDistribution, zip_safe=False, ) diff --git a/build_nuitka_linux.py b/build_nuitka_linux.py index 52906a7..d17b5bc 100644 --- a/build_nuitka_linux.py +++ b/build_nuitka_linux.py @@ -106,6 +106,17 @@ setup( 'orisys': ['*.so', 'configs/*.json'], }}, include_package_data=True, + install_requires=[ + "numpy>=1.24.4", + "opencv-python>=4.10.0.84", + "opencv-contrib-python", + "scipy>=1.10.1", + ], + extras_require={{ + "cuda12": ["cupy-cuda12x>=12.3.0"], + "cuda13": ["cupy-cuda13x>=13.0.0"], + "cuda": ["cupy-cuda12x>=12.3.0"], # For backward compatibility, defaults to CUDA 12.x + }}, distclass=BinaryDistribution, zip_safe=False, ) diff --git a/example1_basic_pipeline.py b/example1_basic_pipeline.py index 5afe942..f50126c 100644 --- a/example1_basic_pipeline.py +++ b/example1_basic_pipeline.py @@ -17,13 +17,12 @@ import numpy as np def main(): # 步骤1:创建传感器对象 (必要步骤),config_name为配置文件名(内置配置文件名)或路径(自定义配置文件路径) - # 方式1: 从视频文件读取 - sensor = orisys.Sensor("s1.mp4", isstitch=True, cuda=True, verbose=True,config_name="prototype") + sensor = orisys.Sensor("s1.mp4", config_name="prototype", cal_path= "./config/cal.npy", isstitch=True, cuda=True, verbose=True) # 方式2: 从摄像头读取(取消注释使用) - # sensor = orisys.Sensor(0, cuda=True, verbose=True, config_name="prototype") + # sensor = orisys.Sensor(0, config_name="prototype", cal_path= "./config/cal.npy", isstitch=True, cuda=True, verbose=True) print("\n按 'q' 退出程序,按 'r' 重置光流追踪器") diff --git a/example2_two_sensor_pipeline.py b/example2_two_sensor_pipeline.py index 75dc749..ff3085b 100644 --- a/example2_two_sensor_pipeline.py +++ b/example2_two_sensor_pipeline.py @@ -28,7 +28,7 @@ from multiprocessing import Queue, Process import time -def sensor_worker(sensor_id, vid_src, config_name, result_queue, stop_event): +def sensor_worker(sensor_id, vid_src, config_name, cal_path, result_queue, stop_event): """ 传感器工作进程函数 @@ -46,7 +46,8 @@ def sensor_worker(sensor_id, vid_src, config_name, result_queue, stop_event): isstitch=True, cuda=True, verbose=False, # 减少子进程输出 - config_name=config_name + config_name=config_name, + cal_path=cal_path ) print(f"传感器 {sensor_id} 已启动") @@ -116,12 +117,16 @@ def main(): num_sensors = 2 sensor_configs = [ { + 'sensor_id': 0, 'vid_src': './s1.mp4', - 'config_name': 'prototype' + 'config_name': 'prototype', + 'cal_path': './config/cal.npy' }, { + 'sensor_id': 1, 'vid_src': './s1.mp4', # 可以改为不同的视频源或摄像头索引 - 'config_name': 'prototype' + 'config_name': 'prototype', + 'cal_path': './config/cal2.npy' }, ] @@ -138,7 +143,7 @@ def main(): for i, config in enumerate(sensor_configs): p = Process( target=sensor_worker, - args=(i, config['vid_src'], config['config_name'], result_queues[i], stop_events[i]) + args=(i, config['vid_src'], config['config_name'], config['cal_path'], result_queues[i], stop_events[i]) ) p.start() processes.append(p) diff --git a/requirements.txt b/requirements.txt index ef33b23..a09ee14 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,8 @@ -cupy_cuda12x>=12.3.0 +# CuPy - Install the appropriate version based on your CUDA version: +# For CUDA 12.x: pip install cupy-cuda12x>=12.3.0 +# For CUDA 13.x: pip install cupy-cuda13x>=13.0.0 +# Or use extras: pip install orisys[cuda12] or pip install orisys[cuda13] + numpy>=1.24.4 opencv_python>=4.10.0.84 opencv-contrib-python diff --git a/setup.py b/setup.py index 73149ab..c52c9f2 100644 --- a/setup.py +++ b/setup.py @@ -19,9 +19,16 @@ setup( }, include_package_data=True, install_requires=[ - "numpy", - "opencv-python", - "scipy", + "numpy>=1.24.4", + "opencv-python>=4.10.0.84", + "opencv-contrib-python", + "scipy>=1.10.1", ], + extras_require={ + "cuda12": ["cupy-cuda12x>=12.3.0"], + "cuda13": ["cupy-cuda13x>=13.0.0"], + # For backward compatibility, 'cuda' defaults to CUDA 12.x + "cuda": ["cupy-cuda12x>=12.3.0"], + }, python_requires=">=3.8", ) diff --git a/src/orisys/Stitcher.py b/src/orisys/Stitcher.py index 599d5a8..6867466 100644 --- a/src/orisys/Stitcher.py +++ b/src/orisys/Stitcher.py @@ -446,7 +446,7 @@ class Stitcher: n_boxes = 0 bk_thresh = 0 # initial black threshold bk_thresh_step = 5 - bk_thresh_max = 125 + bk_thresh_max = 100 # Also include a low global V threshold to capture colored but dark tiles hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)