update foe to contact for easy understanding
This commit is contained in:
+1
-28
@@ -41,6 +41,7 @@ def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample
|
||||
# 降噪:在计算散度之后对散度图进行平滑
|
||||
divergence = cv2.GaussianBlur(divergence, (0, 0), denoise_sigma)
|
||||
|
||||
divergence = np.where(divergence>0.02, divergence, 0)
|
||||
# 创建掩码
|
||||
valid_mask = magnitude > min_magnitude
|
||||
expansion_mask = (valid_mask & (divergence > expansion_threshold))
|
||||
@@ -130,31 +131,3 @@ def compute_multiple_foe(flow_field, min_magnitude=1.0, expansion_threshold=0.00
|
||||
result['expansion_regions'].append(contour)
|
||||
|
||||
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
|
||||
@@ -52,7 +52,7 @@ class Sensor:
|
||||
# =========================================================================
|
||||
|
||||
def __init__(self, vid_src, isstitch=False, verbose=True, cuda=True,
|
||||
config_name="prototype", cal_path=None, override=False, box=None):
|
||||
config_name="prototype", cal_path=None, override=False, box=None,mirror=True):
|
||||
"""
|
||||
Initialize Sensor with video source and configuration.
|
||||
|
||||
@@ -83,6 +83,7 @@ class Sensor:
|
||||
self.verbose = verbose
|
||||
self.config_name = config_name
|
||||
self.cal_path = cal_path
|
||||
self.mirror = mirror
|
||||
|
||||
# State variables
|
||||
self.stitch_valid = False
|
||||
@@ -183,6 +184,8 @@ class Sensor:
|
||||
if log_timing:
|
||||
timings['total'] = (time.perf_counter() - t_start) * 1000
|
||||
self._print_timings("get_img", timings)
|
||||
if self.mirror:
|
||||
self.img = cv2.flip(self.img, 1)
|
||||
|
||||
return self.img
|
||||
|
||||
@@ -241,13 +244,16 @@ class Sensor:
|
||||
|
||||
return self.flow
|
||||
|
||||
def get_foe(self, multiple_foe=False, min_contour_area=3000, min_magnitude=1.0, expansion_threshold=0.01, downsample_factor=1, kernel_size=(5,5), denoise_sigma=15):
|
||||
def get_contact(self, multiple_foe=False, min_contour_area=3000, min_magnitude=1.0, expansion_threshold=0.01, downsample_factor=1, kernel_size=(5,5), denoise_sigma=15):
|
||||
|
||||
if multiple_foe:
|
||||
return compute_multiple_foe(self.vnormal, min_contour_area=min_contour_area, min_magnitude=min_magnitude, expansion_threshold=expansion_threshold, downsample_factor=downsample_factor, kernel_size=kernel_size, denoise_sigma=denoise_sigma)
|
||||
else:
|
||||
return compute_foe(self.vnormal, min_magnitude=min_magnitude, expansion_threshold=expansion_threshold, downsample_factor=downsample_factor, kernel_size=kernel_size, denoise_sigma=denoise_sigma)
|
||||
|
||||
def get_depth(self, denoise_sigma=15):
|
||||
return getFilteredDensity(self.vnormal, use_cuda=self.cuda)
|
||||
self.depth = getFilteredDensity(self.vnormal, use_cuda=self.cuda)
|
||||
def update(self):
|
||||
"""
|
||||
Convenience method: get_img + compute_deformation in one call.
|
||||
|
||||
Reference in New Issue
Block a user