add focus of expansion (foe) detection

This commit is contained in:
bluepulsar
2025-12-28 12:20:44 +08:00
parent 52a8bf58dc
commit 017561578d
3 changed files with 263 additions and 13 deletions
+20 -11
View File
@@ -19,7 +19,8 @@ from .Stitcher import Stitcher
from .tracker import Tracker
from .nHHD import nHHD
from .getDensity import getFilteredDensity
from . import configs
from . import configs
from .get_depth import *
class Sensor:
@@ -93,7 +94,7 @@ class Sensor:
self.img = None
self.img_filtered = None
self.flow = None
self.normal = None
self.vnormal = None
self.shear = None
self.depth = None
self.n_boxes = None
@@ -217,13 +218,13 @@ class Sensor:
if log_timing: timings['hhd_decompose'] = (time.perf_counter() - t0) * 1000
# Get components
self.normal = self.hhd.get_normal()
self.vnormal = self.hhd.get_normal()
self.shear = self.hhd.get_shear()
# Depth computation
if log_timing: t0 = time.perf_counter()
self.depth = getFilteredDensity(flow, use_cuda=self.cuda)
if log_timing: timings['get_density'] = (time.perf_counter() - t0) * 1000
# # Depth computation
# if log_timing: t0 = time.perf_counter()
# self.depth = getFilteredDensity(self.vnormal, use_cuda=self.cuda)
# if log_timing: timings['get_density'] = (time.perf_counter() - t0) * 1000
# Update state
self.flow = flow
@@ -240,6 +241,13 @@ class Sensor:
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)):
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)
else:
return compute_foe(self.vnormal, min_magnitude=min_magnitude, expansion_threshold=expansion_threshold, downsample_factor=downsample_factor,kernel_size=kernel_size)
def update(self):
"""
Convenience method: get_img + compute_deformation in one call.
@@ -251,7 +259,7 @@ class Sensor:
self.compute_deformation()
return {
'img': self.img, 'flow': self.flow,
'normal': self.normal, 'shear': self.shear, 'depth': self.depth,
'normal': self.vnormal, 'shear': self.shear, 'depth': self.depth,
'fps': self.fps, 'fnormal': self.fnormal,
'fshearx': self.fshearx, 'fsheary': self.fsheary, 'ftor': self.ftor,
}
@@ -271,7 +279,7 @@ class Sensor:
mapping = {
self.info.VRAW: lambda: self.flow if self.flow is not None else np.array([]),
self.info.VNORMAL: lambda: self.normal if self.normal is not None else np.array([]),
self.info.VNORMAL: lambda: self.vnormal if self.vnormal is not None else np.array([]),
self.info.VSHEAR: lambda: self.shear if self.shear is not None else np.array([]),
self.info.FNORMAL: lambda: self.fnormal,
self.info.FSHEARX: lambda: self.fshearx,
@@ -343,7 +351,8 @@ class Sensor:
self.last_log_time = t
# Sync instance variables
for k in ['img', 'flow', 'normal', 'shear', 'depth', 'fnormal', 'fshearx', 'fsheary', 'ftor', 'fps']:
# for k in ['img', 'flow', 'normal', 'shear', 'depth', 'fnormal', 'fshearx', 'fsheary', 'ftor', 'fps']:
for k in ['img', 'flow', 'normal', 'shear', 'fnormal', 'fshearx', 'fsheary', 'ftor', 'fps']:
setattr(self, k, result.get(k))
self.vupdate = True
return result
@@ -543,7 +552,7 @@ class Sensor:
self._queue_put(self._result_queue, {
'img': img, 'flow': flow,
'normal': self.hhd.get_normal(), 'shear': self.hhd.get_shear(),
'depth': getFilteredDensity(flow, use_cuda=self.cuda),
# 'depth': getFilteredDensity(flow, use_cuda=self.cuda),
'fnormal': forces[0], 'fshearx': forces[1],
'fsheary': forces[2], 'ftor': forces[3],
})