-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
93 lines (70 loc) · 2.65 KB
/
run.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import logging
import os
import datetime
import argparse
import tqdm.contrib.logging
from stitcher import main
from grid import create_grid
from machine import create_images
from image_io import write_images, load_images
##
## SETTINGS
##
output_dir = 'Pictures'
x_start = 49
x_end = 224
x_inc = 25 #45
y_start = 43
y_end = 193
y_inc = 15 #25
stabilize_delay = 2.2
stitched_scale = 4
skipped_points = []
vertical_clip_fraction = (9 / 20.25) / 2 * 1.1
horizontal_clip_fraction = (5 / 10.5) / 2 * 1.2
##
## LOAD RESOURCES
##
parser = argparse.ArgumentParser(
prog='Visual Inspection Control',
description='Runs and manages the visual inspection machine',
epilog='Contact Nathan Nguyen for script help')
parser.add_argument('-r', '--reuse', action='store_true', help='Reuse the latest folder')
parser.add_argument('-d', '--dir', type=str, help='Load a specific folder')
parser.add_argument('-g', '--no-grid', action='store_true', help='Disable raw grid creation')
parser.add_argument('-v', '--verbose',
action='store_true') # on/off flag
if __name__ == '__main__':
args = parser.parse_args()
logging.basicConfig(format='%(asctime)s - %(name)-24s - %(levelname)-7s - %(message)s (%(filename)s:%(lineno)d)', level=logging.DEBUG if args.verbose else logging.INFO)
logger = logging.getLogger('main')
with tqdm.contrib.logging.logging_redirect_tqdm():
output_dir = os.path.expanduser(output_dir)
if args.reuse:
all_subdirs = [os.path.join(output_dir, d) for d in os.listdir(output_dir)]
folder = max(all_subdirs, key=os.path.getmtime)
logger.info(f'Loading images from folder {folder}')
np_images = load_images(folder)
elif args.dir:
folder = args.dir
logger.info(f'Loading images from folder {folder}')
np_images = load_images(folder)
else:
logger.info('Scanning images')
start_time = datetime.datetime.now()
np_images = create_images(x_start, x_inc, x_end, y_start, y_inc, y_end, stabilize_delay, skipped_points)
# Make Dirs
folder = os.path.join(output_dir, str(start_time))
# Saving images
logger.info('Saving images')
write_images(np_images, folder, x_start, x_inc, y_start, y_inc, args.verbose)
logger.info('Loaded images')
##
## RUN ANALYSIS
##
if not args.no_grid:
logger.info('Creating grid')
create_grid(np_images, os.path.join(folder, 'grid.jpg'), stitched_scale, x_start, x_inc, y_start, y_inc)
logger.info('Stitchng images')
main(np_images, vertical_clip_fraction, horizontal_clip_fraction, folder, args.verbose)
logger.info('Finished, exiting...')