浏览代码

background estimation

Felix Kleinsteuber 3 年之前
父节点
当前提交
97be1c6157
共有 5 个文件被更改,包括 212 次插入7 次删除
  1. 28 7
      approach1a_basic_frame_differencing.ipynb
  2. 123 0
      approach2_background_estimation.ipynb
  3. 二进制
      approach2_results.npy
  4. 8 0
      py/Labels.py
  5. 53 0
      py/Session.py

文件差异内容过多而无法显示
+ 28 - 7
approach1a_basic_frame_differencing.ipynb


文件差异内容过多而无法显示
+ 123 - 0
approach2_background_estimation.ipynb


二进制
approach2_results.npy


+ 8 - 0
py/Labels.py

@@ -0,0 +1,8 @@
+
+LABELS = {
+    "Beaver_01": {
+        "normal": [3, 4, 5, 48, 49, 50, 51, 52, 53, 54, 55, 78, 79, 80, 106, 107, 108, 109, 110, 113, 115, 132, 145, 147, 148, 149, 150, 193, 194, 195, 196, 197, 198, 199, 200, 217, 218, 219, 220, 372, 373, 374, 375, 399, 400, 401, 402, 403, 404, 405, 418, 419, 420, 425, 460, 463, 464, 465, 477, 478, 479, 480, 645, 665, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690],
+        "small": list(range(86, 106)) + list(range(151, 156)) + [204, 205, 371, 392, 393, 394, 395, 416, 417, 459, 462, 476, 630, 631, 644, 677],
+    }
+}
+

+ 53 - 0
py/Session.py

@@ -140,6 +140,8 @@ class Session:
             raise ValueError(f"Unknown motion file name: {filename}")
             raise ValueError(f"Unknown motion file name: {filename}")
     
     
     def __generate_motion_map(self):
     def __generate_motion_map(self):
+        """Populates self.motion_map which maps dates to motion images
+        """
         if self.motion_map is not None:
         if self.motion_map is not None:
             return
             return
         print("Generating motion map...")
         print("Generating motion map...")
@@ -164,6 +166,57 @@ class Session:
             img = MotionImage(self, filename, self.motion_dates[filename])
             img = MotionImage(self, filename, self.motion_dates[filename])
         return img
         return img
     
     
+    def get_random_motion_image_set(self, day_only=False, night_only=False) -> list:
+        """Returns a list of all motion images with the same date +- 10 min.
+        The date is picked randomly from all available dates.
+        May loop indefinitely if there are no matching motion images.
+
+        Args:
+            day_only (bool, optional): Only pick daytime images. Defaults to False.
+            night_only (bool, optional): Only pick nighttime images. Defaults to False.
+
+        Raises:
+            ValueError: No motion images in session
+
+        Returns:
+            list: Non-empty list of motion images with the same date
+        """
+        self.__generate_motion_map()
+        if len(self.motion_map) == 0:
+            raise ValueError("No motion images in session!")
+        imgs = []
+        date = None
+        while len(imgs) == 0 or (day_only and imgs[0].is_nighttime()) or (night_only and imgs[0].is_daytime()):
+            date = random.choice(list(self.motion_map.keys()))
+            filenames = self.motion_map.get(date, [])
+            imgs = [MotionImage(self, filename, date) for filename in filenames]
+        # include all images within +- 10 min
+        for other_date in self.motion_map.keys():
+            if date != other_date and abs((date - other_date).total_seconds()) <= 60 * 10:
+                filenames = self.motion_map.get(other_date, [])
+                imgs += [MotionImage(self, filename, other_date) for filename in filenames]
+        return imgs
+    
+    def generate_motion_image_sets(self) -> list:
+        self.__generate_motion_map()
+        if len(self.motion_map) == 0:
+            raise ValueError("No motion images in session!")
+        imgs = []
+        dates = sorted(list(self.motion_map.keys()))
+        start_date = dates[0]
+        for date in dates:
+            if abs((date - start_date).total_seconds()) > 60 * 20:
+                # end image time series
+                yield imgs
+                start_date = date
+                imgs = []
+            # continue time series
+            filenames = self.motion_map.get(date, [])
+            imgs += [MotionImage(self, filename, date) for filename in filenames]
+        # end of all time series
+        yield imgs
+
+    
     def get_closest_lapse_images(self, motion_file: str):
     def get_closest_lapse_images(self, motion_file: str):
         """Returns the lapse images taken closest before and after this image, respectively.
         """Returns the lapse images taken closest before and after this image, respectively.
         If no such image is found, the corresponding returned image will be None.
         If no such image is found, the corresponding returned image will be None.

部分文件因为文件数量过多而无法显示