add motion detect & fix linux build
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.0 MiB |
@@ -33,6 +33,9 @@ def main():
|
||||
# 步骤 2.1: 获取并拼接图像 (必要步骤)
|
||||
sensor.get_img()
|
||||
print("img_size_raw:", sensor.img_size_raw)
|
||||
if sensor.detect_motion():
|
||||
print("motion detected")
|
||||
break
|
||||
# 步骤 2.2: 计算形变场 (必要步骤)
|
||||
sensor.compute_deformation()
|
||||
# 步骤 2.3: 计算触碰点
|
||||
|
||||
+24
-9
@@ -96,6 +96,7 @@ class Sensor:
|
||||
self.img = None
|
||||
self.img_size_raw = None
|
||||
self.img_filtered = None
|
||||
self.prev_img = None
|
||||
self.flow = None
|
||||
self.vnormal = None
|
||||
self.vshear = None
|
||||
@@ -185,23 +186,37 @@ class Sensor:
|
||||
# Resize
|
||||
img = cv2.resize(img, tuple(self._config_resolution_stitch), interpolation=cv2.INTER_CUBIC)
|
||||
|
||||
# Temporal filtering (noise reduction)
|
||||
alpha = 0.7
|
||||
if self.img_filtered is None:
|
||||
self.img_filtered = img.astype(np.float32)
|
||||
else:
|
||||
self.img_filtered = alpha * img + (1 - alpha) * self.img_filtered
|
||||
# # Temporal filtering (noise reduction)
|
||||
# alpha = 0.7
|
||||
# if self.img_filtered is None:
|
||||
# self.img_filtered = img.astype(np.float32)
|
||||
# else:
|
||||
# self.img_filtered = alpha * img + (1 - alpha) * self.img_filtered
|
||||
# Update previous image
|
||||
if self.mirror:
|
||||
img = cv2.flip(img, 1)
|
||||
|
||||
self.img = self.img_filtered.astype(np.uint8)
|
||||
if self.img is not None:
|
||||
self.prev_img = self.img.copy()
|
||||
|
||||
self.img = img.astype(np.uint8)
|
||||
|
||||
if self.prev_img is None:
|
||||
self.prev_img = img.copy()
|
||||
|
||||
if log_timing:
|
||||
timings['total'] = (time.perf_counter() - t_start) * 1000
|
||||
self._print_timings("get_img", timings)
|
||||
if self.mirror:
|
||||
self.img = cv2.flip(self.img, 1)
|
||||
|
||||
|
||||
return self.img.copy()
|
||||
|
||||
def detect_motion(self, threshold=10):
|
||||
if self.prev_img is None:
|
||||
return False
|
||||
diff = cv2.absdiff(self.img, self.prev_img)
|
||||
return diff.mean() > threshold
|
||||
|
||||
def compute_deformation(self):
|
||||
"""
|
||||
Compute optical flow and decompose into force components.
|
||||
|
||||
Reference in New Issue
Block a user