From b3524d5268a840730b9f4ddf10d5fcfd39047edd Mon Sep 17 00:00:00 2001 From: Sean Danischevsky <105913234+seaniedan-flwls@users.noreply.github.com> Date: Thu, 29 May 2025 11:21:38 +0100 Subject: [PATCH 1/2] don't overwrite when more than one photo in input folder current script overwrites photo_0 if there are more than 1 images in the folder --- main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 9bae472..7c48c8b 100644 --- a/main.py +++ b/main.py @@ -153,7 +153,7 @@ def extract_photos(image_path, output_folder, debug_folder): # Debug: Draw all contours debug_image = padded_image.copy() cv2.drawContours(debug_image, contours, -1, (0, 255, 0), 2) - cv2.imwrite(os.path.join(debug_folder, "debug_all_contours.png"), debug_image) + cv2.imwrite(os.path.join(debug_folder, f"debug_all_contours_{image_path}.png"), debug_image) # Loop through contours and extract rectangular photos photo_count = 0 @@ -175,7 +175,7 @@ def extract_photos(image_path, output_folder, debug_folder): # Debug: Save the transformed photo before cropping white margins cv2.imwrite( - os.path.join(debug_folder, f"debug_transformed_{photo_count}.png"), + os.path.join(debug_folder, f"debug_transformed_{image_path}_{photo_count}.png"), photo, ) @@ -186,7 +186,7 @@ def extract_photos(image_path, output_folder, debug_folder): photo = crop_edges(photo, 5) # Save the photo - output_path = os.path.join(output_folder, f"photo_{photo_count}.png") + output_path = os.path.join(output_folder, f"{image_path}_{photo_count}.png") cv2.imwrite(output_path, photo) photo_count += 1 else: @@ -200,7 +200,7 @@ def extract_photos(image_path, output_folder, debug_folder): # Debug: Save the transformed photo before cropping white margins cv2.imwrite( os.path.join( - debug_folder, f"debug_transformed_skew_{photo_count}.png" + debug_folder, f"debug_transformed_skew_{image_path}_{photo_count}.png" ), photo, ) @@ -212,7 +212,7 @@ def extract_photos(image_path, output_folder, debug_folder): photo = crop_edges(photo, 5) # Save the photo - output_path = os.path.join(output_folder, f"photo_{photo_count}.png") + output_path = os.path.join(output_folder, f"{image_path}_{photo_count}.png") cv2.imwrite(output_path, photo) photo_count += 1 From ae722ad8cf103a1eba8966271ad4babdf0158b5b Mon Sep 17 00:00:00 2001 From: Sean Danischevsky <105913234+seaniedan-flwls@users.noreply.github.com> Date: Thu, 29 May 2025 11:35:55 +0100 Subject: [PATCH 2/2] Update output filenames to not overwrite output and debug filenames now have image name so that they do not overwrite if there are more than one input images in the input folder. --- main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 7c48c8b..1b831db 100644 --- a/main.py +++ b/main.py @@ -153,7 +153,7 @@ def extract_photos(image_path, output_folder, debug_folder): # Debug: Draw all contours debug_image = padded_image.copy() cv2.drawContours(debug_image, contours, -1, (0, 255, 0), 2) - cv2.imwrite(os.path.join(debug_folder, f"debug_all_contours_{image_path}.png"), debug_image) + cv2.imwrite(os.path.join(debug_folder, f"debug_all_contours_{os.path.basename(image_path)}.png"), debug_image) # Loop through contours and extract rectangular photos photo_count = 0 @@ -175,7 +175,7 @@ def extract_photos(image_path, output_folder, debug_folder): # Debug: Save the transformed photo before cropping white margins cv2.imwrite( - os.path.join(debug_folder, f"debug_transformed_{image_path}_{photo_count}.png"), + os.path.join(debug_folder, f"debug_transformed_{os.path.basename(image_path)}_{photo_count}.png"), photo, ) @@ -186,7 +186,7 @@ def extract_photos(image_path, output_folder, debug_folder): photo = crop_edges(photo, 5) # Save the photo - output_path = os.path.join(output_folder, f"{image_path}_{photo_count}.png") + output_path = os.path.join(output_folder, f"{os.path.basename(image_path)}_{photo_count}.png") cv2.imwrite(output_path, photo) photo_count += 1 else: @@ -200,7 +200,7 @@ def extract_photos(image_path, output_folder, debug_folder): # Debug: Save the transformed photo before cropping white margins cv2.imwrite( os.path.join( - debug_folder, f"debug_transformed_skew_{image_path}_{photo_count}.png" + debug_folder, f"debug_transformed_skew_{os.path.basename(image_path)}_{photo_count}.png" ), photo, ) @@ -212,7 +212,7 @@ def extract_photos(image_path, output_folder, debug_folder): photo = crop_edges(photo, 5) # Save the photo - output_path = os.path.join(output_folder, f"{image_path}_{photo_count}.png") + output_path = os.path.join(output_folder, f"{os.path.basename(image_path)}_{photo_count}.png") cv2.imwrite(output_path, photo) photo_count += 1