This repository was archived by the owner on Sep 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
48 lines (39 loc) · 2.11 KB
/
Copy pathcli.py
File metadata and controls
48 lines (39 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
"""CLI Image Processor for Find By Color"""
import argparse
import pathlib
import sys
import tracemalloc
import warnings
from src.config import COLOR_LIMIT, COLOR_TOLERANCE, MAX_IMAGE_SIZE
from src.util import extract_color, ranged_int, max_image_size
# Disable Warning generated by External Model
warnings.filterwarnings("ignore")
# Setup CLI Parser
parser = argparse.ArgumentParser(prog='fbc-process-image', description="Color Extractor", epilog="Find By Color - Color Extractor", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('filename', type=pathlib.Path, help="Source location")
parser.add_argument('-d', '--dest', type=pathlib.Path, metavar='\b', help="Destination location", required=True)
parser.add_argument('-l', '--limit', type=ranged_int(1, 12), metavar='\b', default=COLOR_LIMIT, help="Limit of Extracted Colors [1-12]")
parser.add_argument('-m', '--max-size', type=max_image_size(512, 1024), metavar='\b', default=MAX_IMAGE_SIZE, help="Max Image Size before Resize [512-1024]")
parser.add_argument('-t', '--tolerance', type=ranged_int(0, 100), metavar='\b', default=COLOR_TOLERANCE, help="Threshold to Group Related Colors [0-100]")
parser.add_argument('--debug', metavar='\b', action=argparse.BooleanOptionalAction, help="Print Output to Terminal")
parser.add_argument('--images', metavar='\b', action=argparse.BooleanOptionalAction, help="Generate Images")
parser.add_argument('--json', metavar='\b', action=argparse.BooleanOptionalAction, help="Generate JSON Data")
parser.add_argument('--trace', metavar='\b', action=argparse.BooleanOptionalAction, help="Trace Memory Allocations")
args = parser.parse_args()
config = vars(args)
# Run Function with Configs
if __name__ == '__main__':
if config["trace"] is True:
tracemalloc.start(10)
if config["images"] is True or config["json"] is True:
config["make_color_chart"] = True
extract_color(config)
else:
parser.print_help()
sys.exit(1)
if config["trace"] is True:
profiler.snapshot()
profiler.display_stats()
profiler.compare()
profiler.print_trace()