diff options
author | salvadh0r <dhor@toxic.net.pl> | 2011-11-13 19:58:06 +0100 |
---|---|---|
committer | salvadh0r <dhor@toxic.net.pl> | 2011-11-13 19:58:06 +0100 |
commit | 858ff7b8509cfc6bceb8ce871b77bbbe4453ef5e (patch) | |
tree | cf42b47cc3986f6a413c0acccd1b1a4876ba0f62 /macrofusion.py | |
parent | a10a6c2fdc1e3170fc20404e78fddeaf0cc8b08a (diff) | |
download | macrofusion-code-858ff7b8509cfc6bceb8ce871b77bbbe4453ef5e.zip macrofusion-code-858ff7b8509cfc6bceb8ce871b77bbbe4453ef5e.tar.gz macrofusion-code-858ff7b8509cfc6bceb8ce871b77bbbe4453ef5e.tar.bz2 |
Auto align images
Diffstat (limited to 'macrofusion.py')
-rwxr-xr-x | macrofusion.py | 125 |
1 files changed, 91 insertions, 34 deletions
diff --git a/macrofusion.py b/macrofusion.py index 32aa10d..c7828c4 100755 --- a/macrofusion.py +++ b/macrofusion.py @@ -15,6 +15,7 @@ try: import multiprocessing import re import ConfigParser + import operator except: print('An error occured. Python or one of its sub modules is absent...\nIt would be wise to check your python installation.') sys.exit(1) @@ -33,6 +34,11 @@ except: print('gtk2, pygtk or libglade is missing.') sys.exit(1) +# Bad, bad, really bad coder... Global variables... +global session_images_bak +session_images_bak=[] +global session_options_bak +session_options_bak=[] APP = 'MacroFusion' @@ -63,18 +69,15 @@ locale.setlocale(locale.LC_ALL, '') #gettext.textdomain(APP) #gettext.install(APP) _ = gettext.gettext - - gobject.threads_init() #Pour que les threads soient lancés au moment opportun. - - def toggled_cb(cell, path, user_data): model, column = user_data model[path][column] = not model[path][column] return - + +# PLEASE REAPAIR!! Python-imaging can't open .tiff (or some of them) def creer_miniature(chemin,taille): outfile=donnees.previs_dossier + '/' + os.path.split(chemin)[1] try: @@ -82,11 +85,10 @@ def creer_miniature(chemin,taille): im.thumbnail(taille) im.save(outfile, "JPEG") except IOError: - print _("Generating %s thumbnail failed.") % infile + print _("Generating %s thumbnail failed.") % chemin return outfile - #################################################### ########Classe des données########################## #################################################### @@ -212,10 +214,7 @@ class Interface: self.progressbar = self.gui.get_widget("progressbar") self.checkbuttonexif = self.gui.get_widget("checkbuttonexif") - - if not donnees.check_install('exiftool'): - self.messageinthebottle(_("Exiftool missing!\n\n Cannot copy exif info.")) - + #valeurs des options et configurations : self.check_pyramidelevel = self.gui.get_widget("check_pyramidelevel") self.spinbuttonlevel = self.gui.get_widget("spinbuttonlevel") @@ -252,10 +251,27 @@ class Interface: self.checkbuttonjpegorig = self.gui.get_widget("checkbuttonjpegorig") self.hscalecomprjpeg = self.gui.get_widget("hscalecomprjpeg") self.combtiff = self.gui.get_widget("combtiff") - + + self.checkbutton_a5_align = self.gui.get_widget("checkbutton_a5_align") + self.checkbutton_a5_crop = self.gui.get_widget("checkbutton_a5_crop") + self.checkbutton_a5_shift = self.gui.get_widget("checkbutton_a5_shift") + self.checkbutton_a5_field = self.gui.get_widget("checkbutton_a5_field") + self.combobox_desatmet.set_active(0) self.combtiff.set_active(0) + + if not donnees.check_install('exiftool'): + self.checkbuttonexif.set_sensitive(False) + self.messageinthebottle(_("Exiftool is missing!\n\n Cannot copy exif info.")) + if not donnees.check_install('align_image_stack'): + self.checkbutton_a5_align.set_sensitive(False) + self.checkbutton_a5_crop.set_sensitive(False) + self.checkbutton_a5_field.set_sensitive(False) + self.checkbutton_a5_shift.set_sensitive(False) + #self.checkbutton_a5_align.set_sensitive(False) + self.messageinthebottle(_("Hugin tools (align_image_stack) are missing !\n\n Cannot auto align images.")) + # Read values from config self.conf = ConfigParser.ConfigParser() if os.path.isfile(donnees.enfuse_dossier + '/mfusion.cfg'): @@ -288,6 +304,8 @@ class Interface: self.hscalecomprjpeg.set_value(self.conf.getfloat('prefs', 'jpegcompr')) if self.conf.has_option('prefs', 'tiffcomp'): self.combtiff.set_active(self.conf.getint('prefs', 'tiffcomp')) + if self.conf.has_option('prefs', 'exif'): + self.checkbuttonexif.set_active(self.conf.getboolean('prefs', 'exif')) #On relie les signaux (cliques sur boutons, cochage des cases, ...) aux fonctions appropriées dic = { "on_mainwindow_destroy" : self.exit_app, @@ -324,6 +342,7 @@ class Interface: sys.exit(0) def cleanup(self): + # os.remove(donnees.enfuse_dossier + "/session.sav") for self.files in os.walk(donnees.previs_dossier): for self.filename in self.files[2]: os.remove(donnees.previs_dossier + "/" + self.filename) @@ -383,13 +402,24 @@ class Interface: for item in self.ref: if item: item=-1 - self.thread_preview = Thread_Preview(self.taille, self.get_options(), self.liststoreimport) + self.thread_preview = Thread_Preview(self.taille, self.get_options(), self.get_options_align(), self.liststoreimport) self.thread_preview.start() timer = gobject.timeout_add (100, self.pulsate) break if item==0: self.messageinthebottle(_("Please add some images!\n\n Can't fuse anything.")) - + + def get_options_align(self): + self.options_align=[] + if self.checkbutton_a5_align.get_active(): + if self.checkbutton_a5_crop.get_active(): + self.options_align.append('-C') + if self.checkbutton_a5_shift.get_active(): + self.options_align.append('-i') + if self.checkbutton_a5_field.get_active(): + self.options_align.append('-m') + return self.options_align + def get_options(self): options=["--exposure-weight=" + str(self.spinbuttonexp.get_value()), "--exposure-mu=" + str(self.spinbuttonmu.get_value()), @@ -413,15 +443,11 @@ class Interface: opts+=str(self.spinbuttonLceS.get_value()) + '%:' else: opts+=str(self.spinbuttonLceS.get_value()) + ':' - if self.check_lcef.get_active(): opts+=str(self.spinbuttonLceF.get_value()) + '%' else: opts+=str(self.spinbuttonLceF.get_value()) + '' - options.append(opts) - - # + str(self.spinbuttonLceF.get_value()) + '%') if self.check_ciecam.get_active(): options.append('-c') @@ -461,8 +487,6 @@ class Interface: self.imagepreview.set_from_file(donnees.previs_dossier + "/preview.jpg") # self.buttonbeforeafter.set_label("gfdgdf") - - def fusion(self,widget): FenPar=Fenetre_Parcourir() self.name = FenPar.get_name() @@ -472,31 +496,38 @@ class Interface: self.enroute('') def sendto(self, widget): - self.name=(donnees.previs_dossier + "/sendto.jpg") + self.name=(donnees.previs_dossier + "/sendto.tif") if self.enroute(self.name) == -1: self.messageinthebottle(_("No preview, no output, no edit.\n\n Game Over.")) return def messageinthebottle(self, message): - self.messaga=gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=_(message)) + self.messaga=gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format=(message)) if self.messaga.run() == gtk.RESPONSE_OK: self.messaga.destroy() def enroute(self, issend): self.issend=issend self.liste_images=[] + self.liste_aligned=[] + index = 0 for item in self.liststoreimport: if item[0]: self.liste_images.append(item[2]) + self.liste_aligned.append(donnees.previs_dossier + "/out" + format(index, "04d") + ".tif") + index += 1 + if not Gui.checkbutton_a5_align.get_active(): + self.liste_aligned=self.liste_images if self.liste_images.count(self.name): self.messageinthebottle(_("Can't overwrite input image!\n\n Please change the output filename.")) return -1 if len(self.liste_images) == 0: self.messageinthebottle(_("Please add some images!\n\n Can't fuse anything.")) return -1 - command=[Gui.enfuser, "-o", self.name] + self.get_options() + self.liste_images - ProFus=Progress_Fusion(command, self.issend) + command_a=['align_image_stack', '-a', donnees.previs_dossier + '/out'] + self.get_options_align() + self.liste_images + command=[Gui.enfuser, "-o", self.name] + self.get_options() + self.liste_aligned + ProFus=Progress_Fusion(command, command_a, self.liste_aligned, self.issend) def apropos(self, widget): @@ -520,6 +551,7 @@ class Interface: conf.set('prefs', 'jpegdef', self.checkbuttonjpegorig.get_active()) conf.set('prefs', 'jpegcompr', int(self.hscalecomprjpeg.get_value())) conf.set('prefs', 'tiffcomp', str(self.combtiff.get_active())) + conf.set('prefs', 'exif', str(self.checkbuttonexif.get_active())) if not os.path.exists(donnees.enfuse_dossier): os.makedirs(donnees.enfuse_dossier) @@ -610,23 +642,43 @@ class Fenetre_Parcourir: ##################################################################### class Thread_Preview(threading.Thread): - def __init__(self, taille, options, liste): + def __init__(self, taille, options, options_align, liste): threading.Thread.__init__ (self) self.taille=taille self.options=options self.liste=liste - + self.options_align=options_align + def run(self): images_a_fusionner=[] - + images_a_align=[] + index = 0 + global session_images_bak + global session_options_bak + for item in self.liste: if item[0]: chemin_miniature=creer_miniature(item[2],(int(self.taille[0]), int(self.taille[1]))) - images_a_fusionner.append(chemin_miniature) + images_a_align.append(chemin_miniature) + images_a_fusionner.append(donnees.previs_dossier + "/test" + format(index, "04d") + ".tif") + index += 1 + if not Gui.checkbutton_a5_align.get_active(): + images_a_fusionner=images_a_align if os.path.exists(donnees.previs_dossier + "/preview.jpg"): shutil.copy(donnees.previs_dossier + "/" + "preview.jpg", donnees.previs_dossier + "/" + "preview_.jpg") + if Gui.checkbutton_a5_align.get_active() and \ + (len(images_a_align) != len(session_images_bak) \ + or len(self.options_align) != len(session_options_bak) \ + or len(list(axz for axz in images_a_align if axz not in session_images_bak)) \ + or len(list(axz2 for axz2 in self.options_align if axz2 not in session_options_bak))): + command=["align_image_stack", "-a", donnees.previs_dossier + "/test"] + self.options_align + images_a_align + Gui.statusbar.push(15, _(":: Align photos...")) + preview_process=subprocess.Popen(command, stdout=subprocess.PIPE) + preview_process.wait() + session_options_bak=self.options_align + session_images_bak=images_a_align + Gui.statusbar.push(15, _(":: Fusion photos...")) command=[Gui.enfuser, "-o", donnees.previs_dossier + "/" + "preview.jpg"] + self.options + images_a_fusionner - # print (command) preview_process=subprocess.Popen(command, stdout=subprocess.PIPE) preview_process.wait() @@ -637,8 +689,8 @@ class Thread_Preview(threading.Thread): ####################################################################### class Progress_Fusion: - def __init__(self, command, issend): - self.issend=issend + def __init__(self, command, command_a, liste_aligned, issend): + self.progress = gtk.glade.XML(fname=UI + "Progress.glade", domain=APP) self.progress_win = self.progress.get_widget("dialog1") self.progress_label = self.progress.get_widget("progress_label") @@ -650,7 +702,7 @@ class Progress_Fusion: self.progress.signal_autoconnect(self.dic1) self.info_label.set_text(_('Fusion images...')) - self.thread_fusion = Thread_Fusion(command, self.issend) #On prepare le thread qui va faire tout le boulot + self.thread_fusion = Thread_Fusion(command, command_a, liste_aligned, issend) #On prepare le thread qui va faire tout le boulot self.thread_fusion.start() #On le lance timer = gobject.timeout_add (100, self.pulsate) @@ -675,17 +727,22 @@ class Progress_Fusion: ############################################################################## class Thread_Fusion(threading.Thread): - def __init__(self, command, issend): + def __init__(self, command, command_a, liste_aligned, issend): threading.Thread.__init__ (self) self.command=command + self.command_a=command_a self.issend=issend + self.liste_aligned=liste_aligned def run(self): + if Gui.checkbutton_a5_align.get_active(): + align_process=subprocess.Popen(self.command_a, stdout=subprocess.PIPE) + align_process.wait() fusion_process=subprocess.Popen(self.command, stdout=subprocess.PIPE) fusion_process.wait() # fusion_process=subprocess.call(self.command) if Gui.checkbuttonexif.get_active(): - exif_copy = subprocess.Popen(["exiftool", "-tagsFromFile", "-overwrite_original", Gui.liste_images[0], Gui.name]) + exif_copy = subprocess.Popen(["exiftool", "-tagsFromFile", Gui.liste_images[0], "-overwrite_original", Gui.name]) exif_copy.wait() if len(self.issend) > 0: subprocess.Popen(['gimp', self.issend], stdout=subprocess.PIPE) |