update example and coomputation dependency error handling
This commit is contained in:
+27
-13
@@ -53,16 +53,16 @@ class Sensor:
|
||||
# Initialization
|
||||
# =========================================================================
|
||||
|
||||
def __init__(self, vid_src, isstitch=False, verbose=True, cuda=True,
|
||||
config_name="prototype", cal_path=None, override=False, box=None,mirror=True):
|
||||
def __init__(self, vid_src, cuda=True, isstitch=True, verbose=True,
|
||||
config_name="prototype", cal_path=None, override=False, box=None, mirror=True):
|
||||
"""
|
||||
Initialize Sensor with video source and configuration.
|
||||
|
||||
Args:
|
||||
vid_src: Video source (int for camera ID, str for file path)
|
||||
cuda: Enable CUDA acceleration (default: True)
|
||||
isstitch: Enable stitching mode for multi-tile sensor (default: False)
|
||||
verbose: Print initialization logs (default: True)
|
||||
cuda: Enable CUDA acceleration (default: True)
|
||||
config_name: Configuration name (default: "prototype")
|
||||
cal_path: Path to calibration file (default: None)
|
||||
override: Skip auto-detection, use provided box (default: False)
|
||||
@@ -89,9 +89,9 @@ class Sensor:
|
||||
|
||||
# State variables
|
||||
self.stitch_valid = False
|
||||
self.imgupdate = False
|
||||
self.vupdate = False
|
||||
self.stitch_calibration = []
|
||||
self.compute_deformation_valid = False
|
||||
self.compute_contact_valid = False
|
||||
|
||||
# Data Variables
|
||||
self.__img = None
|
||||
@@ -193,7 +193,6 @@ class Sensor:
|
||||
self.__img_filtered = alpha * img + (1 - alpha) * self.__img_filtered
|
||||
|
||||
self.__img = self.__img_filtered.astype(np.uint8)
|
||||
self.__imgupdate = True
|
||||
|
||||
if log_timing:
|
||||
timings['total'] = (time.perf_counter() - t_start) * 1000
|
||||
@@ -210,6 +209,8 @@ class Sensor:
|
||||
Returns:
|
||||
np.ndarray: Optical flow field
|
||||
"""
|
||||
if self.__img is None:
|
||||
raise Exception("Warning: Get image first")
|
||||
if log_timing:
|
||||
timings = {}
|
||||
t_start = time.perf_counter()
|
||||
@@ -245,9 +246,7 @@ class Sensor:
|
||||
|
||||
# Update state
|
||||
self.__flow = flow
|
||||
self.imgupdate = False
|
||||
self.vupdate = True
|
||||
|
||||
self.compute_deformation_valid = True
|
||||
# FPS calculation
|
||||
self._fps = 1.0 / (time.perf_counter() - self.last_log_time)
|
||||
self.last_log_time = time.perf_counter()
|
||||
@@ -258,8 +257,13 @@ class Sensor:
|
||||
|
||||
return True
|
||||
|
||||
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):
|
||||
def compute_contact(self):
|
||||
|
||||
multiple_foe=False
|
||||
|
||||
if not self.compute_deformation_valid:
|
||||
raise Exception("Warning: Compute deformation first")
|
||||
|
||||
if multiple_foe:
|
||||
result = self.__contact3d.compute_multiple_foe(self.__vnormal)
|
||||
else:
|
||||
@@ -274,6 +278,7 @@ class Sensor:
|
||||
self.__contour = result['contour']
|
||||
self.__depth_map = result['divergence_map']
|
||||
|
||||
self.compute_contact_valid = True
|
||||
return True
|
||||
|
||||
|
||||
@@ -307,9 +312,18 @@ class Sensor:
|
||||
Returns:
|
||||
Tuple: Requested data in order
|
||||
"""
|
||||
if not self.vupdate:
|
||||
print("Warning: Call compute_deformation() first.")
|
||||
|
||||
if any(arg in [self.info.IMG] for arg in args):
|
||||
if self.__img is None:
|
||||
raise Exception("Warning: Get image first")
|
||||
|
||||
if any(arg in [self.info.VRAW, self.info.VNORMAL, self.info.VSHEAR, self.info.FNORMAL, self.info.FSHEARX, self.info.FSHEARY] for arg in args):
|
||||
if not self.compute_deformation_valid:
|
||||
raise Exception("Warning: Compute deformation first")
|
||||
|
||||
if any(arg in [self.info.CENTROID, self.info.CONTOUR, self.info.DEPTH] for arg in args):
|
||||
if not self.compute_contact_valid:
|
||||
raise Exception("Warning: Compute contact first")
|
||||
|
||||
mapping = {
|
||||
# Return copies of arrays to prevent external modification of internal state
|
||||
self.info.VRAW: lambda: self.__flow.copy() if self.__flow is not None else np.array([]),
|
||||
|
||||
Reference in New Issue
Block a user