fixed new sample cannot detect boxes due to filter
This commit is contained in:
+53
-21
@@ -45,6 +45,8 @@ class Sensor:
|
||||
FNORMAL = auto()
|
||||
FSHEARX = auto()
|
||||
FSHEARY = auto()
|
||||
CENTROID = auto()
|
||||
CONTOUR = auto()
|
||||
DEPTH = auto()
|
||||
|
||||
# =========================================================================
|
||||
@@ -91,15 +93,22 @@ class Sensor:
|
||||
self.vupdate = False
|
||||
self.stitch_calibration = []
|
||||
|
||||
# Data variables
|
||||
# Data Variables
|
||||
self.img = None
|
||||
self.img_size_raw = None
|
||||
self.img_filtered = None
|
||||
self.flow = None
|
||||
self.vnormal = None
|
||||
self.shear = None
|
||||
self.depth = None
|
||||
self.vshear = None
|
||||
# self.depth = None
|
||||
self.n_boxes = None
|
||||
self.fnormal = self.fshearx = self.fsheary = self.ftor = 0.0
|
||||
|
||||
# Contact Data Variables
|
||||
self.centroid = None
|
||||
self.centroid_found = False
|
||||
self.contour = None
|
||||
self.depth_map = None
|
||||
|
||||
# Timing
|
||||
self.last_log_time = time.perf_counter()
|
||||
@@ -116,7 +125,11 @@ class Sensor:
|
||||
self._stop_event = None
|
||||
|
||||
# Load configuration
|
||||
self.config_cam = None
|
||||
self.config_stitcher = None
|
||||
self.config_contact = None
|
||||
self._load_config()
|
||||
|
||||
|
||||
# Initialize components
|
||||
self._stitcher = Stitcher(isstitch=isstitch, index=self.config_index)
|
||||
@@ -167,7 +180,8 @@ class Sensor:
|
||||
if log_timing: t0 = time.perf_counter()
|
||||
img = np.ascontiguousarray(self._stitcher.stitch_rt_optimized())
|
||||
if log_timing: timings['stitch'] = (time.perf_counter() - t0) * 1000
|
||||
|
||||
|
||||
self.img_size_raw = img.shape
|
||||
# Resize
|
||||
img = cv2.resize(img, tuple(self.config_resolution_stitch), interpolation=cv2.INTER_CUBIC)
|
||||
|
||||
@@ -222,7 +236,7 @@ class Sensor:
|
||||
|
||||
# Get components
|
||||
self.vnormal = self.hhd.get_normal()
|
||||
self.shear = self.hhd.get_shear()
|
||||
self.vshear = self.hhd.get_shear()
|
||||
|
||||
# # Depth computation
|
||||
# if log_timing: t0 = time.perf_counter()
|
||||
@@ -244,21 +258,31 @@ class Sensor:
|
||||
|
||||
return self.flow
|
||||
|
||||
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):
|
||||
def compute_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:
|
||||
if self.cuda:
|
||||
return compute_foe_gpu(self.vnormal, 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)
|
||||
|
||||
result = 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:
|
||||
if self.cuda:
|
||||
result = compute_foe_gpu(self.vnormal, min_magnitude=min_magnitude, expansion_threshold=expansion_threshold, downsample_factor=downsample_factor, kernel_size=kernel_size, denoise_sigma=denoise_sigma)
|
||||
|
||||
else:
|
||||
result = compute_foe(self.vnormal, min_magnitude=min_magnitude, expansion_threshold=expansion_threshold, downsample_factor=downsample_factor, kernel_size=kernel_size, denoise_sigma=denoise_sigma)
|
||||
|
||||
self.centroid = result['centroid']
|
||||
self.centroid_found = result['centroid_found']
|
||||
if 'contour' in result:
|
||||
self.contour = result['contour']
|
||||
self.depth_map = result['divergence_map']
|
||||
|
||||
return result
|
||||
|
||||
|
||||
# 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 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.
|
||||
@@ -270,7 +294,7 @@ class Sensor:
|
||||
self.compute_deformation()
|
||||
return {
|
||||
'img': self.img, 'flow': self.flow,
|
||||
'normal': self.vnormal, 'shear': self.shear, 'depth': self.depth,
|
||||
'normal': self.vnormal, 'shear': self.vshear, 'depth': self.depth,
|
||||
'fps': self.fps, 'fnormal': self.fnormal,
|
||||
'fshearx': self.fshearx, 'fsheary': self.fsheary, 'ftor': self.ftor,
|
||||
}
|
||||
@@ -291,13 +315,15 @@ class Sensor:
|
||||
mapping = {
|
||||
self.info.VRAW: lambda: self.flow if self.flow 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.VSHEAR: lambda: self.vshear if self.vshear is not None else np.array([]),
|
||||
self.info.FNORMAL: lambda: self.fnormal,
|
||||
self.info.FSHEARX: lambda: self.fshearx,
|
||||
self.info.FSHEARY: lambda: self.fsheary,
|
||||
self.info.FPS: lambda: self.fps,
|
||||
self.info.TIMESTAMP: lambda: time.strftime('%H:%M:%S'),
|
||||
self.info.DEPTH: lambda: self.depth if self.depth is not None else np.array([]),
|
||||
self.info.DEPTH: lambda: self.depth_map if self.depth_map is not None else np.array([]),
|
||||
self.info.CENTROID: lambda: self.centroid if self.centroid is not None else np.array([]),
|
||||
self.info.CONTOUR: lambda: self.contour if self.contour is not None else np.array([]),
|
||||
}
|
||||
|
||||
return tuple(mapping.get(arg, lambda: None)() for arg in args if isinstance(arg, self.info))
|
||||
@@ -431,6 +457,12 @@ class Sensor:
|
||||
self.config_index = cam["index"]
|
||||
self.config_pos_default = cam["pos_default"]
|
||||
|
||||
config_stitcher = self.config["stitcher"]
|
||||
|
||||
config_contact = self.config["contact"]
|
||||
|
||||
|
||||
|
||||
if self.verbose:
|
||||
print(f"Config: {self.config_name}")
|
||||
print(f" Resolution: {self.config_resolution_raw} → {self.config_resolution_stitch}")
|
||||
@@ -579,7 +611,7 @@ class Sensor:
|
||||
while not self._stop_event.is_set():
|
||||
try:
|
||||
img, flow = self._flow_queue.get(timeout=0.1)
|
||||
contact_result = self.get_contact(flow)
|
||||
contact_result = self.compute_contact(flow)
|
||||
self._queue_put(self._result_queue, contact_result)
|
||||
except Empty:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user