Implemented the cli

This commit is contained in:
2023-06-12 08:17:41 +03:00
parent 2b0753247d
commit 523a84742d
2 changed files with 37 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
# Image sorter
+36
View File
@@ -0,0 +1,36 @@
import argparse
from pathlib import Path
from sorter.image_sorter import process_image
# CLI argument parsing
def parse_arguments():
parser = argparse.ArgumentParser(description="Clean images from electricity meter readings.")
parser.add_argument("--source", type=str, help="Path to the input folder containing the images")
parser.add_argument("--destination", type=str, help="Path to the pass folder for images that pass the test")
parser.add_argument("--rejects", type=str, help="Path to the reject folder for images that fail the test")
return parser.parse_args()
def main():
# Parse command-line arguments
args = parse_arguments()
# Set paths for input and output folders
input_folder = Path(args.source)
pass_folder = Path(args.destination)
reject_folder = Path(args.rejects)
# Create output folders if they don't exist
pass_folder.mkdir(parents=True, exist_ok=True)
reject_folder.mkdir(parents=True, exist_ok=True)
# Get the list of image paths in the input folder
image_paths = list(input_folder.glob("*.jpg")) + list(input_folder.glob("*.png"))
# Process the images
for image_path in image_paths:
process_image(image_path, pass_folder, reject_folder)
print("Sorting complete.")
if __name__ == "__main__":
main()