-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_shape_find.py
51 lines (34 loc) · 1.11 KB
/
run_shape_find.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
"""Main control script for shape finding."""
import argparse
import os
import sys
import numpy as np
from python.shape_finder import find_shapes
def main():
"""
Main control function for shape finding.
This function parses command line arguments, loads an input file,
and finds shapes in the image.
Args:
--input-file: Path to the input file.
Returns:
None
"""
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('--input-file', help='Input file', dest='input_file', required=True)
args = parser.parse_args()
# Check input file exists
if not os.path.exists(args.input_file):
print('Input file not found')
sys.exit(1)
# Load input file
with open(args.input_file, 'r') as f:
input_data = f.read()
# Convert input data to an image
image = np.array([[int(x) for x in line] for line in input_data.strip().split('\n')])
# Find shapes
num_shapes, shapes = find_shapes(image)
print(f'Number of shapes in {args.input_file}: {num_shapes}')
if __name__ == '__main__':
main()