diff --git a/config/cal.npy b/config/cal.npy new file mode 100644 index 0000000..e99c32d Binary files /dev/null and b/config/cal.npy differ diff --git a/config/compound_eye.png b/config/compound_eye.png index ef3b17b..e067c53 100644 Binary files a/config/compound_eye.png and b/config/compound_eye.png differ diff --git a/config/demo.json b/config/demo.json deleted file mode 100644 index dc43bd0..0000000 --- a/config/demo.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "demo", - "version": "1.0", - "camera": { - "resolution_raw": [1920, 1080], - "fps": 60, - "units": 15, - "units_used": 9, - "resolution_stitch": [400, 400] - }, - "stitcher": { - "min_area_frac": 0.018, - "max_area_frac": 0.035, - "max_aspect_ratio": 100, - "index": [1, 2, 3, 6, 7, 8, 11, 12, 13], - "margin": 10, - "nominal_ov_pos": 100, - "n": [3, 3] - }, - "tracker": { - "adaptive": true, - "lower_threshold": 12.0, - "upper_threshold": 18.0, - "loop_closure_interval": 1, - "dis_preset": "medium" - }, - "contact": { - "min_contour_area": 3000, - "flow_threshold": 1, - "div_threshold": 0.02, - "expansion_threshold": 0.01, - "kernel_size": [5, 5], - "denoise_sigma": 15 - } -} diff --git a/config/prototype_of1.json b/config/prototype_of1.json new file mode 100644 index 0000000..0c895a0 --- /dev/null +++ b/config/prototype_of1.json @@ -0,0 +1,38 @@ +{ + "name": "prototype", + "version": "1.0", + "camera": { + "resolution_raw": [1920, 1080], + "fps": 60, + "units": 15, + "units_used": 9, + "resolution_stitch": [400, 400] + }, + "stitcher": { + "min_area_frac": 0.018, + "max_area_frac": 0.035, + "max_aspect_ratio": 100, + "index": [1,2,3,6,7,8,11,12,13], + "margin": 10, + "nominal_ov_pos": 100, + "n": [3,3] + }, + "tracker": { + "adaptive": true, + "lower_threshold": 12.0, + "upper_threshold": 18.0, + "loop_closure_interval": 1, + "dis_preset": "medium", + "finest_scale": 1 + }, + "contact": { + "min_contour_area": 3000, + "flow_threshold":1, + "div_threshold":0.02, + "expansion_threshold": 0.01, + "kernel_size": [5,5], + "denoise_sigma": 15 + } +} + + diff --git a/config/prototype_of2.json b/config/prototype_of2.json new file mode 100644 index 0000000..9b6b3d5 --- /dev/null +++ b/config/prototype_of2.json @@ -0,0 +1,38 @@ +{ + "name": "prototype", + "version": "1.0", + "camera": { + "resolution_raw": [1920, 1080], + "fps": 60, + "units": 15, + "units_used": 9, + "resolution_stitch": [400, 400] + }, + "stitcher": { + "min_area_frac": 0.018, + "max_area_frac": 0.035, + "max_aspect_ratio": 100, + "index": [1,2,3,6,7,8,11,12,13], + "margin": 10, + "nominal_ov_pos": 100, + "n": [3,3] + }, + "tracker": { + "adaptive": true, + "lower_threshold": 12.0, + "upper_threshold": 18.0, + "loop_closure_interval": 1, + "dis_preset": "medium", + "finest_scale": 2 + }, + "contact": { + "min_contour_area": 3000, + "flow_threshold":1, + "div_threshold":0.02, + "expansion_threshold": 0.01, + "kernel_size": [5,5], + "denoise_sigma": 15 + } +} + + diff --git a/config/prototype_of3.json b/config/prototype_of3.json new file mode 100644 index 0000000..cf7c989 --- /dev/null +++ b/config/prototype_of3.json @@ -0,0 +1,38 @@ +{ + "name": "prototype", + "version": "1.0", + "camera": { + "resolution_raw": [1920, 1080], + "fps": 60, + "units": 15, + "units_used": 9, + "resolution_stitch": [400, 400] + }, + "stitcher": { + "min_area_frac": 0.018, + "max_area_frac": 0.035, + "max_aspect_ratio": 100, + "index": [1,2,3,6,7,8,11,12,13], + "margin": 10, + "nominal_ov_pos": 100, + "n": [3,3] + }, + "tracker": { + "adaptive": true, + "lower_threshold": 12.0, + "upper_threshold": 18.0, + "loop_closure_interval": 1, + "dis_preset": "medium", + "finest_scale": 3 + }, + "contact": { + "min_contour_area": 3000, + "flow_threshold":1, + "div_threshold":0.02, + "expansion_threshold": 0.01, + "kernel_size": [5,5], + "denoise_sigma": 15 + } +} + + diff --git a/config/stereo.json b/config/stereo.json deleted file mode 100644 index 95d2fe9..0000000 --- a/config/stereo.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "prototype", - "version": "1.0", - "camera": { - "resolution_raw": [1920, 1080], - "fps": 60, - "units": 15, - "units_used": 9, - "resolution_stitch": [400, 400] - }, - "stitcher": { - "min_area_frac": 0.01, - "max_area_frac": 0.05, - "max_aspect_ratio": 100, - "index": [1, 2, 3, 6, 7, 8, 11, 12, 13], - "margin": 10, - "nominal_ov_pos": 100, - "n": [3, 3] - }, - "tracker": { - "adaptive": true, - "lower_threshold": 12.0, - "upper_threshold": 18.0, - "loop_closure_interval": 1, - "dis_preset": "medium" - }, - "contact": { - "min_contour_area": 3000, - "flow_threshold": 1, - "div_threshold": 0.02, - "expansion_threshold": 0.01, - "kernel_size": [5, 5], - "denoise_sigma": 15 - } -} diff --git a/example1_basic_pipeline.py b/example1_basic_pipeline.py index 1c956d0..e2a9232 100644 --- a/example1_basic_pipeline.py +++ b/example1_basic_pipeline.py @@ -19,11 +19,11 @@ def main(): # 步骤1:创建传感器对象 (必要步骤),config_name为配置文件名(内置配置文件名)或路径(自定义配置文件路径) # 方式1: 从视频文件读取 - sensor = orisys.Sensor("s1.mp4", config_name="prototype", cal_path= "./config/cal.npy", isstitch=True, cuda=True, verbose=True) + # sensor = orisys.Sensor("s1.mp4", config_name="./config/prototype_of3.json", cal_path= "./config/cal.npy", isstitch=True, cuda=True, verbose=True) # 方式2: 从摄像头读取(取消注释使用) - # sensor = orisys.Sensor(0, config_name="./config/lens_test.json", cal_path= "./config/cal.npy", isstitch=True, cuda=True, verbose=True) + sensor = orisys.Sensor(0, config_name="./config/prototype_of3.json", cal_path= "./config/cal.npy", isstitch=True, cuda=True, verbose=True) print("\n按 'q' 退出程序,按 'r' 重置光流追踪器") @@ -57,7 +57,7 @@ def main(): arrows = orisys.util.draw_arrows( img, flow, - threshold=5, + threshold=4, grid_spacing=10, arrow_scale=1.0 ) diff --git a/src/orisys/configs/sample_1.json b/src/orisys/configs/sample_1.json deleted file mode 100644 index 25f07bb..0000000 --- a/src/orisys/configs/sample_1.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "prototype", - "version": "1.0", - "camera": { - "resolution_raw": [1920, 1080], - "fps": 60, - "units": 15, - "units_used": 9, - "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]] - }, - "stitcher": { - "min_area_frac": 0.01, - "max_area_frac": 0.05, - "max_aspect_ratio": 100 - }, - "contact": { - "min_contour_area": 3000, - "min_magnitude": 1.0, - "expansion_threshold": 0.01, - "contact_ds_factor": 10, - "kernel_size": [5,5], - "denoise_sigma": 15 - } -} - - diff --git a/src/orisys/sensor.py b/src/orisys/sensor.py index 1f5b9a1..2b87cd9 100644 --- a/src/orisys/sensor.py +++ b/src/orisys/sensor.py @@ -160,11 +160,13 @@ class Sensor: Returns: np.ndarray: Processed grayscale image """ + t0 = time.perf_counter() ret, frame = self.cap.read() if not ret: print("Failed to get_img from video source.") return None - + t1 = time.perf_counter() + print(f"read frame time: {t1 - t0} seconds") # Convert to grayscale gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) diff --git a/src/orisys/tracker.py b/src/orisys/tracker.py index 68cd336..a4871b9 100644 --- a/src/orisys/tracker.py +++ b/src/orisys/tracker.py @@ -1,8 +1,5 @@ import cv2 import numpy as np -import cupy as cp -import time - class Tracker: def __init__(self, @@ -146,12 +143,9 @@ class Tracker: self.__checkLoopClosure(frame) # CPU optical flow computation - start_time = time.perf_counter() self.__prev_fine_flow = self.__tracking_inst.calc( self.__fine_base_frame_queue[-1], frame, self.__prev_fine_flow) - end_time = time.perf_counter() - print(f"CPU optical flow computation time: {end_time - start_time} seconds") # Direct numpy addition is faster than cv2.add final_flow = self.__fine_flow_queue[-1] + self.__prev_fine_flow