optical flow optimize done and cleaned

This commit is contained in:
unknown
2026-01-14 10:13:19 +08:00
parent 4d6bfb49ae
commit 721dccbab4
11 changed files with 120 additions and 108 deletions
BIN
View File
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

-35
View File
@@ -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
}
}
+38
View File
@@ -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
}
}
+38
View File
@@ -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
}
}
+38
View File
@@ -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
}
}
-35
View File
@@ -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
}
}
+3 -3
View File
@@ -19,11 +19,11 @@ def main():
# 步骤1:创建传感器对象 (必要步骤),config_name为配置文件名(内置配置文件名)或路径(自定义配置文件路径) # 步骤1:创建传感器对象 (必要步骤),config_name为配置文件名(内置配置文件名)或路径(自定义配置文件路径)
# 方式1: 从视频文件读取 # 方式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: 从摄像头读取(取消注释使用) # 方式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' 重置光流追踪器") print("\n按 'q' 退出程序,按 'r' 重置光流追踪器")
@@ -57,7 +57,7 @@ def main():
arrows = orisys.util.draw_arrows( arrows = orisys.util.draw_arrows(
img, img,
flow, flow,
threshold=5, threshold=4,
grid_spacing=10, grid_spacing=10,
arrow_scale=1.0 arrow_scale=1.0
) )
-28
View File
@@ -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
}
}
+3 -1
View File
@@ -160,11 +160,13 @@ class Sensor:
Returns: Returns:
np.ndarray: Processed grayscale image np.ndarray: Processed grayscale image
""" """
t0 = time.perf_counter()
ret, frame = self.cap.read() ret, frame = self.cap.read()
if not ret: if not ret:
print("Failed to get_img from video source.") print("Failed to get_img from video source.")
return None return None
t1 = time.perf_counter()
print(f"read frame time: {t1 - t0} seconds")
# Convert to grayscale # Convert to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
-6
View File
@@ -1,8 +1,5 @@
import cv2 import cv2
import numpy as np import numpy as np
import cupy as cp
import time
class Tracker: class Tracker:
def __init__(self, def __init__(self,
@@ -146,12 +143,9 @@ class Tracker:
self.__checkLoopClosure(frame) self.__checkLoopClosure(frame)
# CPU optical flow computation # CPU optical flow computation
start_time = time.perf_counter()
self.__prev_fine_flow = self.__tracking_inst.calc( self.__prev_fine_flow = self.__tracking_inst.calc(
self.__fine_base_frame_queue[-1], frame, self.__fine_base_frame_queue[-1], frame,
self.__prev_fine_flow) 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 # Direct numpy addition is faster than cv2.add
final_flow = self.__fine_flow_queue[-1] + self.__prev_fine_flow final_flow = self.__fine_flow_queue[-1] + self.__prev_fine_flow