remove depth and fix normal -> vnormal

This commit is contained in:
bluepulsar
2025-12-28 18:52:55 +08:00
parent 6ec9eaa334
commit 4192683271
12 changed files with 54 additions and 60 deletions
+1 -1
View File
@@ -75,7 +75,7 @@ def _sensor_worker(sensor_id, config, data_queue, stop_event, use_async=False):
'sensor_id': sensor_id,
'img': sensor.img.copy() if sensor.img is not None else None,
'flow': sensor.flow.copy() if sensor.flow is not None else None,
'normal': sensor.normal.copy() if sensor.normal is not None else None,
'normal': sensor.vnormal.copy() if sensor.vnormal is not None else None,
'shear': sensor.shear.copy() if sensor.shear is not None else None,
'depth': sensor.depth.copy() if sensor.depth is not None else None,
'fps': sensor.fps,
+32 -3
View File
@@ -1,7 +1,8 @@
import numpy as np
import cv2
from scipy.ndimage import gaussian_filter
def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample_factor=10, return_all_contours=False, kernel_size=(5,5), denoise_sigma=1.5):
def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample_factor=10, return_all_contours=False, kernel_size=(5,5), denoise_sigma=10):
"""
计算光流场的扩张焦点(Focus of Expansion)。
@@ -87,7 +88,7 @@ def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample
return result
def compute_multiple_foe(flow_field, min_magnitude=1.0, expansion_threshold=0.001,
downsample_factor=10, min_contour_area=3000, denoise_sigma=1.5, kernel_size=(5,5)):
downsample_factor=10, min_contour_area=3000, denoise_sigma=10, kernel_size=(5,5)):
"""
计算光流场的多个扩张焦点(Foci of Expansion)。
@@ -141,4 +142,32 @@ def compute_multiple_foe(flow_field, min_magnitude=1.0, expansion_threshold=0.00
result['foe_points'].append((cx, cy))
result['expansion_regions'].append(contour)
return result
return result
def smooth_magnitude(mag, method='moving_average', window_size=5, downsample_factor=4):
"""
平滑幅度图以减少梯度计算时的伪影。
Args:
mag: 幅度图,形状为 (H, W) 的 numpy 数组
method: 平滑方法,'moving_average' 或 'windowed_interpolation'
window_size: 移动平均的窗口大小(默认5)
downsample_factor: 窗口插值的下采样因子(默认4)
Returns:
np.ndarray: 平滑后的幅度图
"""
if method == 'moving_average':
# 使用移动平均滤波器(box filter)
kernel = np.ones((window_size, window_size), dtype=np.float32) / (window_size * window_size)
mag_smooth = cv2.filter2D(mag, -1, kernel)
elif method == 'windowed_interpolation':
# 使用窗口插值:下采样然后插值回原尺寸
h, w = mag.shape
mag_downsampled = mag[::downsample_factor, ::downsample_factor]
mag_smooth = cv2.resize(mag_downsampled, (w, h), interpolation=cv2.INTER_CUBIC)
else:
# 默认使用高斯滤波
mag_smooth = gaussian_filter(mag, sigma=1.5)
return mag_smooth