mirror of
https://github.com/andwati/image-sort.git
synced 2026-10-18 08:22:55 +00:00
feat: added multithreading
This commit is contained in:
@@ -173,3 +173,4 @@ pyrightconfig.json
|
|||||||
rejects/
|
rejects/
|
||||||
done/
|
done/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
image_sorter.log
|
||||||
@@ -42,3 +42,4 @@ python cli.py --source <image folder path> --destination <pass folder> --rejects
|
|||||||
- Remove blurry images
|
- Remove blurry images
|
||||||
- Use multithreading to increase performance
|
- Use multithreading to increase performance
|
||||||
- Remove images with no meter readings
|
- Remove images with no meter readings
|
||||||
|
- Progress functionality
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import argparse
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import cv2
|
import cv2
|
||||||
from sorter.image_sorter import process_image
|
from sorter.image_sorter import process_image
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
# CLI argument parsing
|
# CLI argument parsing
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
@@ -35,14 +36,16 @@ def main():
|
|||||||
image_paths = list(input_folder.glob("*.jpg")) + list(input_folder.glob("*.png"))
|
image_paths = list(input_folder.glob("*.jpg")) + list(input_folder.glob("*.png"))
|
||||||
|
|
||||||
# Process the images
|
# Process the images
|
||||||
for image_path in image_paths:
|
with ThreadPoolExecutor() as executor:
|
||||||
"""
|
for image_path in image_paths:
|
||||||
try catch block to handle errors in processing individual images.
|
"""
|
||||||
"""
|
try catch block to handle errors in processing individual images.
|
||||||
try:
|
"""
|
||||||
process_image(image_path, pass_folder, reject_folder)
|
try:
|
||||||
except cv2.error as e:
|
#process_image(image_path, pass_folder, reject_folder)
|
||||||
print(f"Error processing image {image_path.name}: {str(e)}")
|
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.")
|
print("Sorting complete.")
|
||||||
|
|
||||||
|
|||||||
@@ -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")
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" , datefmt="%Y-%m-%d %H:%M:%S")
|
||||||
logger = logging.getLogger(__name__)
|
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):
|
def is_image_below_threshold(image_path, size_threshold):
|
||||||
"""Check if the image size is below the threshold.
|
"""Check if the image size is below the threshold.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user