Added docstrings for documentation

This commit is contained in:
2023-06-16 09:17:48 +03:00
parent 7b20711720
commit 009c6ea029
4 changed files with 22 additions and 11 deletions
+2
View File
@@ -39,4 +39,6 @@ python cli.py --source <image folder path> --destination <pass folder> --rejects
- Sort images according to size
- Remove black or blank images
- Remove white/gray images
- Remove blurry images
- Use multithreading to increase performance
- Remove images with no meter readings
+7
View File
@@ -5,6 +5,11 @@ from sorter.image_sorter import process_image
# CLI argument parsing
def parse_arguments():
"""Parse command-line arguments.
Returns:
argparse.Namespace: Parsed command-line 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")
@@ -12,6 +17,8 @@ def parse_arguments():
return parser.parse_args()
def main():
"""Main entry point of the program."""
# Parse command-line arguments
args = parse_arguments()
+13 -11
View File
@@ -11,15 +11,17 @@ threshold_type = cv2.THRESH_BINARY
def is_image_below_threshold(image_path, size_threshold):
"""If the image size is below the threshold, regardless of the thresholding
result, the image will be moved to the reject folder.
"""Check if the image size is below the threshold.
If the image size is below the threshold, regardless of the thresholding result,
the image will be moved to the reject folder.
Args:
image_path (_type_): _description_
size_threshold (_type_): _description_
image_path (str): Path to the image file.
size_threshold (int): Size threshold in bytes.
Returns:
_type_: _description_
bool: True if the image size is below the threshold, False otherwise.
"""
image_path = Path(image_path)
size = image_path.stat().st_size
@@ -27,20 +29,20 @@ def is_image_below_threshold(image_path, size_threshold):
def process_image(image_path,pass_folder,reject_folder,size_threshold=75*1024):
"""_summary_
"""Process an image by applying thresholding and moving it to the appropriate folder.
Args:
image_path (_type_): _description_
pass_folder (_type_): _description_
reject_folder (_type_): _description_
size_threshold (_type_, optional): _description_. Defaults to 75*1024.
image_path (str): Path to the image file.
pass_folder (str): Path to the pass folder for images that pass the test.
reject_folder (str): Path to the reject folder for images that fail the test.
size_threshold (int, optional): Size threshold in bytes. Defaults to 75*1024.
"""
image_path = Path(image_path)
filename = image_path.name
image = cv2.imread(str(image_path))
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# threshold(src, dst, threshold value, max value, threshold type)
# Apply thresholding (src, dst, threshold value, max value, threshold type)
_, threshold = cv2.threshold(gray, threshold_value, max_value, threshold_type)
View File