-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
50 lines (37 loc) · 1.52 KB
/
main.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
"""Main module containing script entry - main function"""
import cv2 as cv
from shared import Debug
from argsparser import parser, parse_argument
from preprocessing import preprocess
from segmentation import segment
from topology_recognition import recognize_topology
from postprocessing import postprocess
def main():
args = parser.parse_args()
mode, debug, file_path, save_path = parse_argument(args)
if mode == -1 or debug == -1 or len(save_path) == 0:
print("1: Error reading input arguments!")
return -1
source = cv.imread(file_path)
if source is not None: # read successful, process image
# 1st step - preprocessing
source, preprocessed, mode, is_rotated = preprocess(source, mode, debug)
# 2nd step - segmentation
vertices_list, visualised, preprocessed, edge_thickness = segment(source, preprocessed, mode, debug)
if len(vertices_list) == 0:
print("1: No vertices found")
return -1
# 3rd step - topology recognition
vertices_list = recognize_topology(vertices_list, preprocessed, visualised, edge_thickness, mode, debug)
# 4th step - postprocessing
postprocess(vertices_list, save_path, is_rotated)
# if displaying debug info has been enabled keep displayed windows open until key is pressed
if debug != Debug.NO:
cv.waitKey(0)
print("0")
return 0
else:
print("1: Error opening image!")
return -1
if __name__ == "__main__":
main()