diff --git a/config/cal.npy b/config/cal.npy deleted file mode 100644 index 36f9a7b..0000000 Binary files a/config/cal.npy and /dev/null differ diff --git a/config/compound_eye.png b/config/compound_eye.png index 5bf2d0a..ef3b17b 100644 Binary files a/config/compound_eye.png and b/config/compound_eye.png differ diff --git a/example1_basic_pipeline.py b/example1_basic_pipeline.py index f50126c..d7b2616 100644 --- a/example1_basic_pipeline.py +++ b/example1_basic_pipeline.py @@ -32,6 +32,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: 计算触碰点 diff --git a/src/orisys/sensor.py b/src/orisys/sensor.py index 906d4b3..2d406fb 100644 --- a/src/orisys/sensor.py +++ b/src/orisys/sensor.py @@ -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 - - self.img = self.img_filtered.astype(np.uint8) + # # 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) + + 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.