update doc
This commit is contained in:
+37
-21
@@ -60,7 +60,7 @@ class Sensor:
|
||||
# =========================================================================
|
||||
|
||||
def __init__(self, vid_src, cuda=True, isstitch=True, verbose=True, debug=False,
|
||||
config_name="prototype", cal_path=None, override=False, box=None, mirror=True, poisson_backend='auto'):
|
||||
config_name="prototype", cal_path=None, override=False, box=None, mirror=True, backend='auto'):
|
||||
"""
|
||||
Initialize Sensor with video source and configuration.
|
||||
|
||||
@@ -73,6 +73,11 @@ class Sensor:
|
||||
cal_path: Path to calibration file (default: None)
|
||||
override: Skip auto-detection, use provided box (default: False)
|
||||
box: Manual bounding boxes when override=True (default: None)
|
||||
backend: Poisson backend (default: "auto")
|
||||
"auto": Automatically select the best backend based on availability
|
||||
"cupy": Use CuPy for GPU acceleration
|
||||
"opencl": Use OpenCL for GPU acceleration
|
||||
"cpu": Use CPU for computation
|
||||
"""
|
||||
|
||||
self.CUPY_AVAILABLE = check_cupy_available()
|
||||
@@ -112,8 +117,9 @@ class Sensor:
|
||||
|
||||
# Optical Flow Data Variables (public)
|
||||
self.flow = np.zeros(shape + (2,), dtype=np.float32)
|
||||
self.vnormal = np.zeros_like(self.flow)
|
||||
self.vshear = np.zeros_like(self.flow)
|
||||
self.vtemplate = np.zeros_like(self.flow)
|
||||
self.vnormal = self.vtemplate
|
||||
self.vshear = self.vtemplate
|
||||
self.n_boxes = None
|
||||
self.fnormal = self.fshearx = self.fsheary = self.ftor = 0.0
|
||||
|
||||
@@ -134,7 +140,7 @@ class Sensor:
|
||||
self.__tracker = Tracker(adaptive=True, cuda=cuda, verbose=self.verbose, config_tracker=self.__config_tracker)
|
||||
self.__contact3d = Contact3D(config_contact=self.__config_contact, verbose=self.verbose)
|
||||
self.__hhd = None
|
||||
self.poisson_backend = poisson_backend
|
||||
self.poisson_backend = backend
|
||||
self._use_pyav = False
|
||||
self._av_container = None
|
||||
self._av_stream = None
|
||||
@@ -211,15 +217,16 @@ class Sensor:
|
||||
self._fps = 1.0 / (time.perf_counter() - self.last_log_time)
|
||||
self.last_log_time = time.perf_counter()
|
||||
|
||||
return None
|
||||
return self.img.copy()
|
||||
|
||||
def detect_motion(self, threshold=4):
|
||||
if self.initial_img is None:
|
||||
return False
|
||||
diff = cv2.absdiff(self.img, self.initial_img)
|
||||
return diff.mean() > threshold
|
||||
def detect_motion(self, threshold=6):
|
||||
|
||||
def compute_deformation(self, decompose=True):
|
||||
# detect motion by optical flow magnitude
|
||||
mag = np.linalg.norm(self.flow, axis=1)
|
||||
# print(f"mag: {mag.max()}, {mag.min()}, {mag.mean()}")
|
||||
return mag.mean() > threshold
|
||||
|
||||
def compute_deformation(self, decompose=True, check_motion=True, threshold=6):
|
||||
"""
|
||||
Compute optical flow and decompose into force components.
|
||||
|
||||
@@ -230,10 +237,19 @@ class Sensor:
|
||||
raise Exception("Warning: Get image first")
|
||||
|
||||
self.compute_flow()
|
||||
if decompose:
|
||||
self.compute_hhd()
|
||||
# self.compute_hhd()
|
||||
if check_motion:
|
||||
if self.detect_motion(threshold=threshold):
|
||||
self.compute_hhd()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
if decompose:
|
||||
self.compute_hhd()
|
||||
|
||||
return True
|
||||
return None
|
||||
# return True
|
||||
|
||||
def compute_flow(self):
|
||||
if self.img is None:
|
||||
@@ -326,14 +342,14 @@ class Sensor:
|
||||
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:
|
||||
print("Warning: Compute deformation first")
|
||||
# raise Exception("Warning: Compute deformation 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:
|
||||
# print("Warning: Compute deformation first")
|
||||
# # 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:
|
||||
print("Warning: Compute contact first")
|
||||
# if any(arg in [self.info.CENTROID, self.info.CONTOUR, self.info.DEPTH] for arg in args):
|
||||
# if not self.compute_contact_valid:
|
||||
# print("Warning: Compute contact first")
|
||||
# raise Exception("Warning: Compute contact first")
|
||||
|
||||
mapping = {
|
||||
|
||||
Reference in New Issue
Block a user