|
7 | 7 | from multiprocessing import Pool |
8 | 8 | import numpy as np |
9 | 9 | from PIL import Image |
10 | | -from distutils.util import strtobool |
11 | 10 | import os |
12 | 11 | from datetime import datetime |
13 | 12 | from pathlib import Path |
@@ -889,25 +888,31 @@ def _convert_str_to_int(x): |
889 | 888 | except: |
890 | 889 | return x |
891 | 890 |
|
| 891 | + def _strtobool(value: str) -> bool: |
| 892 | + value = value.lower() |
| 893 | + if value in ("y", "yes", "on", "1", "true", "t"): |
| 894 | + return True |
| 895 | + return False |
| 896 | + |
892 | 897 | if __name__ == '__main__': |
893 | 898 | # Parameters for when launching difPy via CLI |
894 | 899 | parser = argparse.ArgumentParser(description='Find duplicate or similar images with difPy - https://github.com/elisemercury/Duplicate-Image-Finder') |
895 | 900 | parser.add_argument('-D', '--directory', type=str, nargs='+', help='Paths of the directories to be searched. Default is working dir.', required=False, default=[os.getcwd()]) |
896 | 901 | parser.add_argument('-Z', '--output_directory', type=str, help='Output directory path for the difPy result files. Default is working dir.', required=False, default=None) |
897 | | - parser.add_argument('-r', '--recursive', type=lambda x: bool(strtobool(x)), help='Search recursively within the directories.', required=False, choices=[True, False], default=True) |
898 | | - parser.add_argument('-i', '--in_folder', type=lambda x: bool(strtobool(x)), help='Search for matches in the union of directories.', required=False, choices=[True, False], default=False) |
899 | | - parser.add_argument('-le', '--limit_extensions', type=lambda x: bool(strtobool(x)), help='Limit search to known image file extensions.', required=False, choices=[True, False], default=True) |
| 902 | + parser.add_argument('-r', '--recursive', type=lambda x: bool(_help._strtobool(x)), help='Search recursively within the directories.', required=False, choices=[True, False], default=True) |
| 903 | + parser.add_argument('-i', '--in_folder', type=lambda x: bool(_help._strtobool(x)), help='Search for matches in the union of directories.', required=False, choices=[True, False], default=False) |
| 904 | + parser.add_argument('-le', '--limit_extensions', type=lambda x: bool(_help._strtobool(x)), help='Limit search to known image file extensions.', required=False, choices=[True, False], default=True) |
900 | 905 | parser.add_argument('-px', '--px_size', type=int, help='Compression size of images in pixels.', required=False, default=50) |
901 | 906 | parser.add_argument('-s', '--similarity', type=_help._convert_str_to_int, help='Similarity grade (mse).', required=False, default='duplicates') |
902 | | - parser.add_argument('-ro', '--rotate', type=lambda x: bool(strtobool(x)), help='Rotate images during comparison process.', required=False, choices=[True, False], default=True) |
903 | | - parser.add_argument('-la', '--lazy', type=lambda x: bool(strtobool(x)), help='Compares image dimensions before comparison process.', required=False, choices=[True, False], default=True) |
| 907 | + parser.add_argument('-ro', '--rotate', type=lambda x: bool(_help._strtobool(x)), help='Rotate images during comparison process.', required=False, choices=[True, False], default=True) |
| 908 | + parser.add_argument('-la', '--lazy', type=lambda x: bool(_help._strtobool(x)), help='Compares image dimensions before comparison process.', required=False, choices=[True, False], default=True) |
904 | 909 | parser.add_argument('-mv', '--move_to', type=str, help='Output directory path of lower quality images among matches.', required=False, default=None) |
905 | | - parser.add_argument('-d', '--delete', type=lambda x: bool(strtobool(x)), help='Delete lower quality images among matches.', required=False, choices=[True, False], default=False) |
906 | | - parser.add_argument('-sd', '--silent_del', type=lambda x: bool(strtobool(x)), help='Suppress the user confirmation when deleting images.', required=False, choices=[True, False], default=False) |
907 | | - parser.add_argument('-p', '--show_progress', type=lambda x: bool(strtobool(x)), help='Show the real-time progress of difPy.', required=False, choices=[True, False], default=True) |
| 910 | + parser.add_argument('-d', '--delete', type=lambda x: bool(_help._strtobool(x)), help='Delete lower quality images among matches.', required=False, choices=[True, False], default=False) |
| 911 | + parser.add_argument('-sd', '--silent_del', type=lambda x: bool(_help._strtobool(x)), help='Suppress the user confirmation when deleting images.', required=False, choices=[True, False], default=False) |
| 912 | + parser.add_argument('-p', '--show_progress', type=lambda x: bool(_help._strtobool(x)), help='Show the real-time progress of difPy.', required=False, choices=[True, False], default=True) |
908 | 913 | parser.add_argument('-proc', '--processes', type=_help._convert_str_to_int, help=' Number of worker processes for multiprocessing.', required=False, default=None) |
909 | 914 | parser.add_argument('-ch', '--chunksize', type=_help._convert_str_to_int, help='Only relevant when dataset > 5k images. Sets the batch size at which the job is simultaneously processed when multiprocessing.', required=False, default=None) |
910 | | - parser.add_argument('-l', '--logs', type=lambda x: bool(strtobool(x)), help='(Deprecated) Collect statistics during the process.', required=False, choices=[True, False], default=None) |
| 915 | + parser.add_argument('-l', '--logs', type=lambda x: bool(_help._strtobool(x)), help='(Deprecated) Collect statistics during the process.', required=False, choices=[True, False], default=None) |
911 | 916 |
|
912 | 917 | args = parser.parse_args() |
913 | 918 |
|
|
0 commit comments