-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLS_GUI.py
More file actions
688 lines (535 loc) · 21.5 KB
/
Copy pathLS_GUI.py
File metadata and controls
688 lines (535 loc) · 21.5 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
# © 2024 Regents of the University of Minnesota. All rights reserved.
# This program is shared under the terms and conditions of the GNU General Public License 3.0, License. Further details about the GNU GPL 3.0 license are available in the license.txt file
"""
To run app, navigate to directory using the that contains LS_GUI.py using terminal. Then type:
$ pythonw LS_GUI.py
"""
import ctypes
import ctypes.util
import os
import wx
import wx.lib.agw.multidirdialog as MDD
import cv2
import numpy
import multiprocessing
import shutil
import sys
from imutils import paths
from pathlib import Path
import threading
import os
if os.name == 'nt':
vipshome = 'c:\\vips-dev\\bin'
os.environ['PATH'] = vipshome + ';' + os.environ['PATH']
# required by pyinstaller
#import pkg_resources.py2_warn
if __name__ == "__main__":
multiprocessing.freeze_support()
from PyQt5.QtWidgets import (QFileDialog, QAbstractItemView, QListView,
QTreeView, QApplication, QDialog)
import _thread
from os.path import isfile, isdir, join
from os.path import expanduser
import stitcher
from stitcher import Stitcher
import subprocess
from subprocess import DEVNULL, STDOUT, check_call
import statistics
from config import LSConfig;
from string import Template
import threading
from queue import Queue
import time
from Preferences import PreferencesEditor;
from zipfile import ZipFile
class LinearStitch(wx.Frame):
# Our normal wxApp-derived class, as usual
# app = wx.App(0)
#setup listbox list as global var
init_list = []
cont = None
scalePath = ""
scaleControl = None
progressGauge = None
ScanQueue = Queue()
FocusQueue = Queue()
StitchQueue = Queue()
StackQueue = Queue()
ArchiveQueue = Queue()
def __init__(self, parent, title):
self.config = LSConfig()
for w in range(int(self.config.configValues["CoreCount"])):
t = threading.Thread(target=self.scanWorker, name='worker-%s' % w)
t.daemon = True
t.start()
for w in range(int(self.config.configValues["CoreCount"])):
t = threading.Thread(target=self.focusWorker, name='worker-%s' % w)
t.daemon = True
t.start()
t = threading.Thread(target=self.stitchWorker, name='worker-%s' % w)
t.daemon = True
t.start()
t = threading.Thread(target=self.stackWorker, name='worker-%s' % w)
t.daemon = True
t.start()
t = threading.Thread(target=self.archiveWorker, name='worker-%s' % w)
t.daemon = True
t.start()
wx.Frame.__init__(self, parent, -1, title,
pos=(150, 150), size=(600, 600))
#panel setup for button and listbox use
panel = wx.Panel(self)
self.myPanel = panel
# Create the menubar
menuBar = wx.MenuBar()
# and a menu
menu = wx.Menu()
# add an item to the menu, using \tKeyName automatically
# creates an accelerator, the third param is some help text
# that will show up in the statusbar
menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")
# bind the menu event to an event handler
self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
# and put the menu on the menubar
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
self.CreateStatusBar()
#app contains 4 buttons for interactive use
# exitbutton = wx.Button(panel, label="Exit")
clearbutton = wx.Button(panel, label="Clear All")
addbutton = wx.Button(panel, label = "+")
delbutton = wx.Button(panel, label = "-")
self.cont = wx.ListBox(panel, -1, (0,0), (200, 200), self.init_list, wx.LB_EXTENDED)
scale_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
selectScale = wx.Button(panel, label = "Select Scale")
self.scaleControl = wx.TextCtrl(panel, size=(400, -1), style=wx.TE_READONLY)
scale_horzSizer.Add(selectScale, 0, wx.ALL, 10);
scale_horzSizer.Add(self.scaleControl, 0, wx.ALL, 10);
sizer = wx.BoxSizer(wx.VERTICAL)
panelCtrls_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
buttonSizer = wx.BoxSizer(wx.VERTICAL)
buttonSizer.Add(addbutton, 0, wx.ALL, 10)
buttonSizer.Add(delbutton, 0, wx.ALL, 10)
buttonSizer.Add(clearbutton, 0, wx.ALL, 10)
panelCtrls_horzSizer.Add(buttonSizer)
panelCtrls_horzSizer.Add(self.cont)
self.AddLinearSpacer( sizer,10 )
button_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
scanForProblems = wx.Button(panel, label = "Scan for Problems")
removeBlurryImages = wx.Button(panel, label = "Remove Blurry Images")
startProcessing = wx.Button(panel, label = "Start Processing")
showPrefsButton = wx.Button(panel, label = "Prefs")
self.progressGauge = wx.Gauge(panel, range=100, style=wx.GA_HORIZONTAL, size = (100, -1));
button_horzSizer.Add(showPrefsButton, 0, wx.ALL, 10);
button_horzSizer.Add(scanForProblems, 0, wx.ALL, 10);
button_horzSizer.Add(removeBlurryImages, 0, wx.ALL, 10);
button_horzSizer.Add(startProcessing, 0, wx.ALL, 10);
button_horzSizer.Add(self.progressGauge, 0, wx.ALL, 10)
self.progressGauge.Hide();
self.maskBox = wx.CheckBox(panel, label="Mask Images")
self.verticalCore = wx.CheckBox(panel, label="Vertical Core")
self.removeVignette = wx.CheckBox(panel, label="Remove Vignetting")
self.rotateImage = wx.CheckBox(panel, label="Straighten Image")
if (os.name == 'nt' and ctypes.util.find_library('libvips-42') is None and ctypes.util.find_library('libvips') is None):
self.rotateImage.Hide()
self.cropImage = wx.CheckBox(panel, label="Crop Image")
self.cropImage.SetValue(True)
self.stackImages = wx.CheckBox(panel, label="Stack Images")
self.stackImages.SetValue(True)
self.archiveImages = wx.CheckBox(panel, label="Archive Images")
self.archiveImages.SetValue(True)
sizer.Add(panelCtrls_horzSizer)
sizer.Add(scale_horzSizer, 0, wx.ALL, 10)
sizer.Add(self.maskBox, 0, wx.ALL, 10)
sizer.Add(self.verticalCore, 0, wx.ALL, 10)
sizer.Add(self.removeVignette, 0, wx.ALL, 10)
sizer.Add(self.rotateImage, 0, wx.ALL, 10)
sizer.Add(self.cropImage, 0, wx.ALL, 10)
sizer.Add(self.stackImages, 0, wx.ALL, 10)
sizer.Add(self.archiveImages, 0, wx.ALL, 10)
sizer.Add(button_horzSizer, 0, wx.ALL, 10)
panel.SetSizerAndFit(sizer)
panel.Layout()
sizer2 = wx.BoxSizer(wx.VERTICAL)
sizer2.Add(panel, 1, wx.EXPAND)
self.SetSizerAndFit(sizer2)
#event handling - button binded with functions
# self.Bind(wx.EVT_BUTTON, self.on_exit_button, exitbutton)
self.Bind(wx.EVT_BUTTON, self.on_clear_button, clearbutton)
self.Bind(wx.EVT_BUTTON, self.on_add_button, addbutton)
self.Bind(wx.EVT_BUTTON, self.on_del_button, delbutton)
self.Bind(wx.EVT_BUTTON, self.on_scale_button, selectScale)
self.Bind(wx.EVT_BUTTON, self.scanForProblems, scanForProblems)
self.Bind(wx.EVT_BUTTON, self.removeBlurryImages, removeBlurryImages)
self.Bind(wx.EVT_BUTTON, self.startProcessing, startProcessing)
self.Bind(wx.EVT_BUTTON, self.showPrefs, showPrefsButton)
#event handling - close app with "x" button located in corner
self.Bind(wx.EVT_CLOSE, self.on_exit_button)
self.pool=multiprocessing.Pool()
# Create a thread to run the listener function in the background
t = threading.Thread(target=self.listener)
t.daemon = True
t.start()
def listener(self):
while True:
address = ('localhost', 6234) # family is deduced to be 'AF_INET'
listener = multiprocessing.connection.Listener(address, authkey=b'dendroFun')
conn = listener.accept()
print('connection accepted from', listener.last_accepted)
msg = conn.recv()
# do something with msg
print('recieved message: ' + msg )
self.receiveMessage(msg)
conn.close()
listener.close()
def showPrefs(self, event):
self.prefs = PreferencesEditor(self.config)
self.prefs.Show(self)
def AddLinearSpacer( self, boxsizer, pixelSpacing ) :
""" A one-dimensional spacer along only the major axis for any BoxSizer """
orientation = boxsizer.GetOrientation()
if (orientation == wx.HORIZONTAL) :
boxsizer.Add( (pixelSpacing, 0) )
elif (orientation == wx.VERTICAL) :
boxsizer.Add( (0, pixelSpacing) )
def OnTimeToClose(self, evt):
"""Event handler for the button click."""
print("Exiting.")
# self.closewindow(self, evt)
sys.exit()
#opens a new menu and closes when selection(s) is made
#adds currently selected directory/directories to listbox
def on_add_button(self, event):
self.selectFolders()
def on_scale_button(self, event):
dlg = getExistingFiles()
dlg.setDirectory(self.config.configValues["BrowsePath"])
if dlg.exec_() == QDialog.Accepted:
selectedFiles = dlg.selectedFiles()
self.scalePath = selectedFiles[0]
self.scaleControl.SetValue(self.scalePath)
#deletes currently selected directory/directories from listbox
def on_del_button(self,event):
deleted_items = self.cont.GetSelections()
deleted_items.reverse()
for file in deleted_items:
self.cont.Delete(file)
#terminates app
def on_exit_button(self, event):
self.Destroy()
#deletes all current directories in listbox
def on_clear_button(self, event):
while (self.cont.GetCount() != 0):
self.cont.Delete(0)
#closes window, does NOT terminate app
def closewindow(self, event):
self.Destroy()
#obtains path for selected directory to be added to the listbox
def selectFolders(self):
dlg = getExistingDirectories()
dlg.setDirectory(self.config.configValues["BrowsePath"])
if dlg.exec_() == QDialog.Accepted:
self.cont.InsertItems(dlg.selectedFiles(), 0)
def scanForProblems(self, event):
print("Starting Scan")
for folder in self.cont.GetStrings():
# self.scanCore(folder)
self.ScanQueue.put(folder)
def scanWorker(self):
while True:
if not self.ScanQueue.empty():
folder = self.ScanQueue.get()
self.scanCore(folder)
self.ScanQueue.task_done()
time.sleep(1)
def removeBlurryImages(self, event):
print("Starting Blurry Image Removal")
for folder in self.cont.GetStrings():
self.focusCore(folder)
def scanCore(self, folder):
childrenCores = [f for f in os.listdir(folder) if isdir(join(folder, f))]
childrenCores.sort()
fileCountList = [];
outputText = ""
outputText += "Scanning for problems in: " + folder + "\n"
outputText += "------------------------------------" + "\n"
for core in childrenCores:
fileCount = 0
(problemList, fileCount) = self.scanFolder(folder + "/" + core)
fileCountList.append(fileCount)
if(len(problemList) > 0):
for problemFile in problemList:
outputText += "Problem detected in: " + folder + "/" + core + "/" + problemFile + "\n"
if(len(fileCountList) < 2):
outputText += "Empty Folder: " + folder + "/" + "\n"
else:
coreMode = max(set(fileCountList), key=fileCountList.count)
for index, core in enumerate(fileCountList):
if(core != coreMode):
outputText += "File count mismatch in: " + folder + "/" + childrenCores[index] + "\n"
outputText += "------------------------------------" + "\n" + "\n"
self.echo(outputText)
def echo(self, text):
print(text)
def scanFolder(self, path):
files = [f for f in os.listdir(path) if isfile(join(path, f))]
colorAverage = []
fileCount = 0
files.sort()
onlyJpegs = [jpg for jpg in files if jpg.lower().endswith(".jpg")]
if(len(onlyJpegs) < 1):
return [], 0
proc = Processor(path)
# for file in onlyJpegs:
# fileCount += 1
# # myimg = cv2.imread(path + "/" + file)
# # avg_color_per_row = numpy.average(myimg, axis=0)
# # avg_color = numpy.average(avg_color_per_row, axis=0)
# colorAverage.append(avg_color)
colorAverage=self.pool.map(proc,onlyJpegs)
hasProblem = False
meanValues = numpy.array(colorAverage).mean(axis=0)
problemIndex = []
for index, item in enumerate(colorAverage):
distance = numpy.array(item) - meanValues
if(not all(abs(i) <= 20 for i in distance)):
hasProblem = True
problemIndex.append(index)
problemFiles = []
for problemItem in problemIndex:
problemFiles.append(onlyJpegs[problemItem])
return problemFiles, fileCount
def focusWorker(self):
while True:
if not self.FocusQueue.empty():
folder = self.FocusQueue.get()
self.focusFolder(folder)
time.sleep(1)
def focusCore(self, folder):
childrenCores = [f for f in os.listdir(folder) if isdir(join(folder, f))]
childrenCores.sort()
fileCountList = [];
outputText = ""
outputText += "Cleaning blurry images in: " + folder + "\n"
outputText += "------------------------------------" + "\n"
for core in childrenCores:
self.FocusQueue.put(folder + "/" + core)
def echo(self, text):
print(text)
def focusFolder(self, path):
for imagePath in sorted(paths.list_images(path)):
# load the image, convert it to grayscale, and compute the
# focus measure of the image using the Variance of Laplacian
# method
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fm = self.variance_of_laplacian(gray)
if fm > float(self.config.configValues["FocusThreshold"]):
text = imagePath+" - Not Blurry: "+str(fm)
self.echo(imagePath+" - Not Blurry: "+str(fm))
# if the focus measure is less than the supplied threshold,
# then the image should be considered "blurry"
if fm < float(self.config.configValues["FocusThreshold"]):
text = imagePath+" - Blurry: "+str(fm)
self.echo(imagePath+" - Blurry: "+str(fm))
os.rename(imagePath, imagePath + "_blurry")
def variance_of_laplacian(self,image):
# compute the Laplacian of the image and then return the focus
# measure, which is simply the variance of the Laplacian
return cv2.Laplacian(image, cv2.CV_64F).var()
def stitchWorker(self):
while True:
if not self.StitchQueue.empty():
folder = self.StitchQueue.get()
self.stitchFolder(folder)
self.StitchQueue.task_done()
time.sleep(1)
def stackWorker(self):
while True:
if not self.StackQueue.empty():
folder = self.StackQueue.get()
if(self.stackImages.IsChecked):
if(self.config.configValues["StackerSelection"] == "Zerene"):
self.stackZerene(folder)
elif(self.config.configValues["StackerSelection"] == "FocusStack"):
self.stackFocusStack(folder)
self.StackQueue.task_done()
time.sleep(1)
def get_all_file_paths(self, directory):
# initializing empty file paths list
file_paths = []
# crawling through directory and subdirectories
for root, directories, files in os.walk(directory):
for filename in files:
# join the two strings in order to form the full filepath.
filepath = os.path.join(root, filename)
file_paths.append(filepath)
# returning all file paths
return file_paths
def archiveWorker(self):
while True:
if not self.ArchiveQueue.empty():
folder = self.ArchiveQueue.get()
self.archive(folder)
self.ArchiveQueue.task_done()
time.sleep(1)
def archive(self, folder):
ArchivePath = self.config.configValues["ArchivePath"]
if ArchivePath == 'NULL':
print('WARNING: Folder not archived. See Archive option in config.ini file.')
else:
outputFile = os.path.basename(folder) + ".zip"
outputFilePath = os.path.join(self.config.configValues["ArchivePath"], outputFile)
file_paths = self.get_all_file_paths(folder)
print("Zipping to: " + outputFilePath)
with ZipFile(outputFilePath,'w') as zip:
# writing each file one by one
for file in file_paths:
zip.write(file, os.path.relpath(file, os.path.join(folder, '..')))
def startProcessing(self, event):
self.progressGauge.Show()
self.myPanel.Layout();
for folder in self.cont.GetStrings():
onlyFiles = [f for f in os.listdir(folder) if isfile(join(folder, f))]
print(onlyFiles)
print(folder)
if(self.stackImages.IsChecked()):
self.StackQueue.put(folder)
else:
self.StitchQueue.put(folder)
def receiveMessage(self, folder):
if(self.stackImages.IsChecked()):
self.StackQueue.put(folder)
else:
self.StitchQueue.put(folder)
def stackZerene(self, folder):
onlyFolders = [f for f in os.listdir(folder) if isdir(join(folder, f))]
onlyFolders.sort()
sourceString = "";
for stackFolder in onlyFolders:
sourceString += '<Source value="' + folder + "/" + stackFolder + '"/>\n'
substitutionDict = {'batchLength': len(
onlyFolders), 'sourceFiles': sourceString, 'outputPath': folder + "/"}
template = open( self.config.configValues["ZereneTemplateFile"] )
src = Template( template.read() )
populatedTemplate = src.substitute(substitutionDict)
xmlFile = folder + "/stack.xml"
output = open(xmlFile, "w")
output.write(populatedTemplate)
output.close();
ZereneInstall = self.config.configValues["ZereneInstall"]
ZereneLicense = self.config.configValues["ZereneLicense"]
ZereneLicense = ZereneLicense.replace('{{APPDATA}}', os.getenv('APPDATA'))
if not ZereneInstall.endswith('/'):
ZereneInstall += '/'
if not ZereneLicense.endswith('/'):
ZereneLicense += '/'
commandLine = self.config.configValues["ZereneLaunchPath"] \
.replace('{{Install}}', ZereneInstall) \
.replace('{{License}}', ZereneLicense) \
.replace('{{script}}', xmlFile);
subprocess.call( commandLine, stdout=DEVNULL, stderr=subprocess.STDOUT)
self.StitchQueue.put(folder)
def stackFocusStack(self, folder):
onlyFolders = [f for f in os.listdir(folder) if isdir(join(folder, f))]
onlyFolders.sort()
for stackFolder in onlyFolders:
focusStackInstall = self.config.configValues["FocusStackInstall"]
inputPath = ""
if(self.config.configValues["PruneBeforeStacking"]):
files = [f for f in os.listdir(folder + "/" + stackFolder) if isfile(join(folder + "/" + stackFolder, f))]
files.sort()
onlyJpegs = [jpg for jpg in files if jpg.lower().endswith(".jpg")]
if(len(onlyJpegs) < 1):
continue
# sort the files by filesize and remove the smallest 50% of them files
fileSizes = []
for file in onlyJpegs:
fileSizes.append(os.path.getsize(folder + "/" + stackFolder + "/" + file))
median = statistics.median(fileSizes)
for file in onlyJpegs:
if(os.path.getsize(folder + "/" + stackFolder + "/" + file) >= median):
inputPath = inputPath + ' "' + folder + "/" + stackFolder + "/" + file + '"'
else:
inputPath = '"' + folder + "/" + stackFolder + "/" + '"' + "*jpg"
commandLine = self.config.configValues["FocusStackLaunchPath"] \
.replace('{{Install}}', focusStackInstall) \
.replace('{{folderPath}}', inputPath) \
.replace('{{outputPath}}', folder + "/" + stackFolder + ".jpg")
print(commandLine);
subprocess.call(commandLine, stdout=DEVNULL,
stderr=subprocess.STDOUT, shell=True)
self.StitchQueue.put(folder)
def stitchFolder(self, targetFolder):
stitcherHandler = Stitcher(float(self.config.configValues["Overlap"]))
filesToStitch = []
onlyFiles = [f for f in os.listdir(targetFolder) if isfile(join(targetFolder, f))]
for files in onlyFiles:
if(files.lower().endswith(".jpg")):
filesToStitch.append(targetFolder + "/" + files)
if(len(filesToStitch) < 2):
return
parentName = os.path.split(os.path.dirname(filesToStitch[0]))[1]
outputFile = os.path.join(os.path.dirname(filesToStitch[0]),parentName + ".tiff")
scaledPreviewFile = os.path.join(os.path.dirname(filesToStitch[0]),parentName + "_preview.jpg")
logFile = os.path.join(os.path.dirname(filesToStitch[0]),parentName + "_log.txt")
filesToStitch.sort()
if(self.config.configValues['RightToLeft'] == True):
filesToStitch.reverse()
print(filesToStitch)
print(outputFile);
print("Logging to: " + logFile);
if(outputFile is None):
exit()
stitcherHandler.stitchFileList(filesToStitch, outputFile, scaledPreviewFile, logFile, self.progressCallback,
self.maskBox.IsChecked(), self.scalePath, self.verticalCore.IsChecked(), self.removeVignette.IsChecked(), float(self.config.configValues["VignetteMagic"]), self.rotateImage.IsChecked(), self.cropImage.IsChecked())
shutil.copy(outputFile, self.config.configValues["CoreOutputPath"])
if(self.archiveImages.IsChecked()):
self.ArchiveQueue.put(targetFolder)
# _thread.start_new_thread(stitcherHandler.stitchFileList, (filesToStitch, outputFile,logFile, self.progressCallback, self.maskBox.IsChecked(), self.scalePath))
def progressCallback(self, status, progress):
self.progressGauge.SetValue(progress);
class getExistingDirectories(QFileDialog):
def __init__(self, *args):
super(getExistingDirectories, self).__init__(*args)
self.setOption(self.DontUseNativeDialog, True)
self.setFileMode(self.Directory)
self.setOption(self.ShowDirsOnly, True)
# self.setDirectory(args[0])
self.findChildren(QListView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)
self.findChildren(QTreeView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)
class getExistingFiles(QFileDialog):
def __init__(self, *args):
super(getExistingFiles, self).__init__(*args)
self.setOption(self.DontUseNativeDialog, True)
self.setFileMode(self.ExistingFile)
self.setOption(self.ShowDirsOnly, False)
class Processor:
def __init__(self,path):
self._path=path
def __call__(self,filename):
myimg = cv2.imread(self._path + "/" + filename)
avg_color_per_row = numpy.average(myimg, axis=0)
avg_color = numpy.average(avg_color_per_row, axis=0)
return avg_color
class CustomOutputWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "LinearStitch Output",
pos=(50, 50), size=(600, 300))
self.text = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.TE_READONLY)
def write(self, text):
wx.CallAfter(self.text.AppendText, text)
class MyApp(wx.App):
def OnInit(self):
self.outputWindow = CustomOutputWindow()
self.outputWindow.Show()
sys.stdout = self.outputWindow
sys.stderr = self.outputWindow
frame = LinearStitch(None, "LinearStitch")
self.SetTopWindow(frame)
frame.Show(True)
return True
if __name__ == '__main__':
qapp = QApplication(sys.argv)
app = MyApp(redirect=True)
app.MainLoop()