feat: added multithreading

This commit is contained in:
2023-06-16 10:25:54 +03:00
parent 4d87850d0e
commit b3b5b94dac
4 changed files with 25 additions and 9 deletions
+1
View File
@@ -173,3 +173,4 @@ pyrightconfig.json
rejects/
done/
.vscode/
image_sorter.log
+1
View File
@@ -42,3 +42,4 @@ python cli.py --source <image folder path> --destination <pass folder> --rejects
- Remove blurry images
- Use multithreading to increase performance
- Remove images with no meter readings
- Progress functionality
+11 -8
View File
@@ -2,6 +2,7 @@ import argparse
from pathlib import Path
import cv2
from sorter.image_sorter import process_image
from concurrent.futures import ThreadPoolExecutor
# CLI argument parsing
def parse_arguments():
@@ -35,14 +36,16 @@ def main():
image_paths = list(input_folder.glob("*.jpg")) + list(input_folder.glob("*.png"))
# Process the images
for image_path in image_paths:
"""
try catch block to handle errors in processing individual images.
"""
try:
process_image(image_path, pass_folder, reject_folder)
except cv2.error as e:
print(f"Error processing image {image_path.name}: {str(e)}")
with ThreadPoolExecutor() as executor:
for image_path in image_paths:
"""
try catch block to handle errors in processing individual images.
"""
try:
#process_image(image_path, pass_folder, reject_folder)
executor.submit(process_image, image_path, pass_folder, reject_folder)
except cv2.error as e:
print(f"Error processing image {image_path.name}: {str(e)}")
print("Sorting complete.")
+11
View File
@@ -14,6 +14,17 @@ threshold_type = cv2.THRESH_BINARY
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" , datefmt="%Y-%m-%d %H:%M:%S")
logger = logging.getLogger(__name__)
# Create a file handler and set the log file path
log_file = "./image_sorter.log"
file_handler = logging.FileHandler(log_file)
# Configure the file handler to use a more verbose log format than the console output
formatter = logging.Formatter("[%(levelname)s] %(asctime)s %(message)s")
file_handler.setFormatter(formatter)
# Add the file handler to the logger
logger.addHandler(file_handler)
def is_image_below_threshold(image_path, size_threshold):
"""Check if the image size is below the threshold.