From 657ac053b643f1dcd0c0c301d095177ad8635b8a Mon Sep 17 00:00:00 2001 From: Hayden Housen Date: Wed, 19 Jul 2023 10:08:18 -0700 Subject: [PATCH] Small edge case fixes --- lecture2notes/end_to_end/helpers.py | 5 ++++- lecture2notes/end_to_end/sift_matcher.py | 6 +++++- lecture2notes/end_to_end/slide_structure_analysis.py | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lecture2notes/end_to_end/helpers.py b/lecture2notes/end_to_end/helpers.py index 7e2aae2..87b6e1e 100644 --- a/lecture2notes/end_to_end/helpers.py +++ b/lecture2notes/end_to_end/helpers.py @@ -40,7 +40,10 @@ def copy_all(list_path_files, output_dir, move=False): def frame_number_from_filename(filename): - return int(re.search(r"(?<=\_)[0-9]+(?=\_|.)", filename).group(0)) + try: + return int(re.search(r"(?<=\_)[0-9]+(?=\_|.)", filename).group(0)) + except AttributeError: + return None def frame_number_filename_mapping(path, filenames_only=True): diff --git a/lecture2notes/end_to_end/sift_matcher.py b/lecture2notes/end_to_end/sift_matcher.py index 1deeaeb..2263230 100644 --- a/lecture2notes/end_to_end/sift_matcher.py +++ b/lecture2notes/end_to_end/sift_matcher.py @@ -241,6 +241,9 @@ def does_camera_move_all_in_folder(folder_path): ] images.sort() + if len(images) < 2: + return 0, 0, 0 + move_values = [] movement_detection_values = [] previous_image = cv2.imread(images[0]) @@ -408,7 +411,7 @@ def match_features( was enabled and no motion was detected. """ if do_motion_detection: - movement_detected = does_camera_move_all_in_folder(presenter_slide_path) + movement_detected = does_camera_move_all_in_folder(presenter_slide_path)[0] > 0.05 else: movement_detected = True @@ -438,6 +441,7 @@ def match_features( all_dst_corners = [] match_successful = False frame_with_most_content = None + dst_coords = None previous_category = images[0][1] for idx, (filename, category) in tqdm( diff --git a/lecture2notes/end_to_end/slide_structure_analysis.py b/lecture2notes/end_to_end/slide_structure_analysis.py index f4cac6d..2c1fd32 100644 --- a/lecture2notes/end_to_end/slide_structure_analysis.py +++ b/lecture2notes/end_to_end/slide_structure_analysis.py @@ -336,6 +336,8 @@ def all_in_folder(path, do_rename=True, **kwargs): if os.path.isfile(current_path): image = cv2.imread(current_path) frame_number = frame_number_from_filename(current_path) + if not frame_number: + continue if do_rename: item_directory = os.path.dirname(item)