-
Notifications
You must be signed in to change notification settings - Fork 1
/
adlc-gui.py
executable file
·113 lines (91 loc) · 4.4 KB
/
adlc-gui.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'
from PyQt5.QtWidgets import (QMainWindow, QWidget, QListView, QPushButton, QScrollArea, QApplication, QHBoxLayout, QVBoxLayout, QFileDialog, QLabel, QAction)
from ui_utils import *
from adlc import ADLCProcessor
class MainWindow(QMainWindow):
def __init__(self, flight_number=0, threads=4, check_interop=True, quit=True):
super(MainWindow, self).__init__(None)
self.quit = quit
self.initUI()
self.initToolbar()
self.processor = ADLCProcessor(flight_number = flight_number, check_interop=check_interop)
self.processor.new_target.connect(self.new_target)
self.processor.new_roi.connect(self.new_roi)
self.processor.processing_finished.connect(self.processing_finished)
def initUI(self):
self.roiDisplayScroll = QScrollArea(self)
self.roiDisplayScroll.setWidgetResizable(True)
self.roiDisplay = QWidget()
self.roiLayout = QVBoxLayout()
self.roiDisplay.setLayout(self.roiLayout)
self.roiDisplayScroll.setWidget(self.roiDisplay)
self.targetDisplayScroll = QScrollArea(self)
self.targetDisplayScroll.setWidgetResizable(True)
self.targetDisplay = QWidget()
self.targetLayout = QVBoxLayout()
self.targetDisplay.setLayout(self.targetLayout)
self.targetDisplayScroll.setWidget(self.targetDisplay)
self.imageryLayout = QHBoxLayout()
self.imageryLayout.addWidget(self.targetDisplayScroll)
self.imageryLayout.addWidget(self.roiDisplayScroll)
centralWidget = QWidget()
centralWidget.setLayout(self.imageryLayout)
self.setCentralWidget(centralWidget)
def initToolbar(self):
saveAction = QAction('Save', self)
saveAction.setShortcut('Ctrl+S')
saveAction.setStatusTip('Save Images')
saveAction.triggered.connect(self.saveImages)
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(saveAction)
def new_target(self, target):
self.targetLayout.addWidget(TargetCanvas(target))
def new_roi(self, roi):
self.roiLayout.addWidget(ROICanvas(roi))
def processing_finished(self):
if(self.quit):
print('Processing finished, exiting...')
QApplication.quit()
def saveImages(self):
saveDirectory = str(QFileDialog.getExistingDirectory(self, "Select a directory to save the output in..."))
try:
if not os.path.isdir(saveDirectory + "/targets"):
os.mkdir(saveDirectory + "/targets")
if not os.path.isdir(saveDirectory + "/fp"):
os.mkdir(saveDirectory + "/fp")
if not os.path.isdir(saveDirectory + "/thumbnail"):
os.mkdir(saveDirectory + "/thumbnail")
if not os.path.isdir(saveDirectory + "/thumbnail/targets"):
os.mkdir(saveDirectory + "/thumbnail/targets")
if not os.path.isdir(saveDirectory + "/thumbnail/fp"):
os.mkdir(saveDirectory + "/thumbnail/fp")
t_n = 0
fp_n = 0
for i in range(self.roiLayout.count()):
local_widget = self.roiLayout.itemAt(i).widget()
if(local_widget.target):
local_widget.saveRoiImage(saveDirectory + "/targets/t{}.jpg".format(t_n))
local_widget.saveThumbnailImage(saveDirectory + "/thumbnail/targets/t{}.jpg".format(t_n))
t_n += 1
else:
local_widget.saveRoiImage(saveDirectory + "/fp/f{}.jpg".format(fp_n))
local_widget.saveThumbnailImage(saveDirectory + "/thumbnail/fp/f{}.jpg".format(fp_n))
fp_n += 1
except Exception as e:
print('While saving images, the following exception occurred:')
print(e)
if __name__=="__main__":
import sys
import argparse
parser = argparse.ArgumentParser(description='Search flight images for targets.')
parser.add_argument("-i", "--input_flight", help="Flight number to search")
parser.add_argument("--no-interop", action="store_true")
parser.add_argument("--no-quit", action="store_true")
args = parser.parse_args()
app = QApplication(sys.argv)
w = MainWindow(flight_number=args.input_flight, check_interop=(not args.no_interop), quit=(not args.no_quit))
w.resize(1600, 900)
w.show()
app.exec_()