Forráskód Böngészése

background estimation

Felix Kleinsteuber 3 éve
szülő
commit
97be1c6157

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 28 - 7
approach1a_basic_frame_differencing.ipynb


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 123 - 0
approach2_background_estimation.ipynb


BIN
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}")
     
     def __generate_motion_map(self):
+        """Populates self.motion_map which maps dates to motion images
+        """
         if self.motion_map is not None:
             return
         print("Generating motion map...")
@@ -164,6 +166,57 @@ class Session:
             img = MotionImage(self, filename, self.motion_dates[filename])
         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):
         """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.

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott