Signed-off-by: bluepulsar <cheungken3@yahoo.com.hk>
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.0 MiB After Width: | Height: | Size: 2.1 MiB |
+1
-1
@@ -57,7 +57,7 @@ def main():
|
|||||||
|
|
||||||
# 计算扩张焦点
|
# 计算扩张焦点
|
||||||
# foe_result = orisys.util.compute_foe(vnormal,min_magnitude=1,expansion_threshold=0.01,downsample_factor=1)
|
# foe_result = orisys.util.compute_foe(vnormal,min_magnitude=1,expansion_threshold=0.01,downsample_factor=1)
|
||||||
foe_result = sensor.get_foe(multiple_foe=False, min_magnitude=1, expansion_threshold=0.01, downsample_factor=1,denoise_sigma=10)
|
foe_result = sensor.get_foe(multiple_foe=False, min_magnitude=1, expansion_threshold=0.01,denoise_sigma=15)
|
||||||
# 在图像上绘制焦点和区域
|
# 在图像上绘制焦点和区域
|
||||||
image_with_foe = orisys.util.draw_foe(sensor.img.copy(), foe_result)
|
image_with_foe = orisys.util.draw_foe(sensor.img.copy(), foe_result)
|
||||||
cv2.imshow("Focus of Expansion", image_with_foe)
|
cv2.imshow("Focus of Expansion", image_with_foe)
|
||||||
|
|||||||
+4
-17
@@ -1,8 +1,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
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=10):
|
def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample_factor=1, return_all_contours=False, kernel_size=(5,5), denoise_sigma=10):
|
||||||
"""
|
"""
|
||||||
计算光流场的扩张焦点(Focus of Expansion)。
|
计算光流场的扩张焦点(Focus of Expansion)。
|
||||||
|
|
||||||
@@ -25,16 +24,9 @@ def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample
|
|||||||
flow_ds = flow_field[::downsample_factor, ::downsample_factor, :]
|
flow_ds = flow_field[::downsample_factor, ::downsample_factor, :]
|
||||||
u_ds, v_ds = flow_ds[:, :, 0], flow_ds[:, :, 1]
|
u_ds, v_ds = flow_ds[:, :, 0], flow_ds[:, :, 1]
|
||||||
|
|
||||||
# 降噪:在计算散度之前对光流场进行平滑
|
|
||||||
if denoise_sigma > 0:
|
|
||||||
u_ds = cv2.GaussianBlur(u_ds, (0, 0), denoise_sigma)
|
|
||||||
v_ds = cv2.GaussianBlur(v_ds, (0, 0), denoise_sigma)
|
|
||||||
|
|
||||||
magnitude_ds = np.sqrt(u_ds**2 + v_ds**2)
|
magnitude_ds = np.sqrt(u_ds**2 + v_ds**2)
|
||||||
|
magnitude_ds = cv2.GaussianBlur(magnitude_ds, (0, 0), denoise_sigma)
|
||||||
divergence_ds = np.gradient(u_ds, axis=1) + np.gradient(v_ds, axis=0)
|
divergence_ds = np.gradient(u_ds, axis=1) + np.gradient(v_ds, axis=0)
|
||||||
|
|
||||||
# 降噪:在计算散度之后对散度图进行平滑
|
|
||||||
if denoise_sigma > 0:
|
|
||||||
divergence_ds = cv2.GaussianBlur(divergence_ds, (0, 0), denoise_sigma)
|
divergence_ds = cv2.GaussianBlur(divergence_ds, (0, 0), denoise_sigma)
|
||||||
|
|
||||||
magnitude = cv2.resize(magnitude_ds, (W, H), interpolation=cv2.INTER_CUBIC)
|
magnitude = cv2.resize(magnitude_ds, (W, H), interpolation=cv2.INTER_CUBIC)
|
||||||
@@ -42,16 +34,11 @@ def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample
|
|||||||
else:
|
else:
|
||||||
u, v = flow_field[:, :, 0], flow_field[:, :, 1]
|
u, v = flow_field[:, :, 0], flow_field[:, :, 1]
|
||||||
|
|
||||||
# 降噪:在计算散度之前对光流场进行平滑
|
|
||||||
if denoise_sigma > 0:
|
|
||||||
u = cv2.GaussianBlur(u, (0, 0), denoise_sigma)
|
|
||||||
v = cv2.GaussianBlur(v, (0, 0), denoise_sigma)
|
|
||||||
|
|
||||||
magnitude = np.sqrt(u**2 + v**2)
|
magnitude = np.sqrt(u**2 + v**2)
|
||||||
|
magnitude = cv2.GaussianBlur(magnitude, (0, 0), denoise_sigma)
|
||||||
divergence = np.gradient(u, axis=1) + np.gradient(v, axis=0)
|
divergence = np.gradient(u, axis=1) + np.gradient(v, axis=0)
|
||||||
|
|
||||||
# 降噪:在计算散度之后对散度图进行平滑
|
# 降噪:在计算散度之后对散度图进行平滑
|
||||||
if denoise_sigma > 0:
|
|
||||||
divergence = cv2.GaussianBlur(divergence, (0, 0), denoise_sigma)
|
divergence = cv2.GaussianBlur(divergence, (0, 0), denoise_sigma)
|
||||||
|
|
||||||
# 创建掩码
|
# 创建掩码
|
||||||
@@ -88,7 +75,7 @@ def compute_foe(flow_field, min_magnitude=1.0, expansion_threshold=1, downsample
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def compute_multiple_foe(flow_field, min_magnitude=1.0, expansion_threshold=0.001,
|
def compute_multiple_foe(flow_field, min_magnitude=1.0, expansion_threshold=0.001,
|
||||||
downsample_factor=10, min_contour_area=3000, denoise_sigma=10, kernel_size=(5,5)):
|
downsample_factor=1, min_contour_area=3000, denoise_sigma=15, kernel_size=(5,5)):
|
||||||
"""
|
"""
|
||||||
计算光流场的多个扩张焦点(Foci of Expansion)。
|
计算光流场的多个扩张焦点(Foci of Expansion)。
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ class Sensor:
|
|||||||
|
|
||||||
return self.flow
|
return self.flow
|
||||||
|
|
||||||
def get_foe(self, multiple_foe=False, min_contour_area=3000, min_magnitude=1.0, expansion_threshold=1, downsample_factor=10, kernel_size=(5,5), denoise_sigma=1.5):
|
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):
|
||||||
|
|
||||||
if multiple_foe:
|
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)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user