Esempio n. 1
0
	def run(self):
		args = list()
		args.append("-o")
		args.append(self.output_file)
		if self.compression:
			args.append('--compression=%s' % str(self.compression))
		if self.gpu:
			args.append('--gpu')
		for arg in self.additional_args:
			args.append(arg)
		for f in self.input_files:
			args.append(f)
		
		for opt in config.enblend_opts().split():
			args.append(opt)
		
		rc = Execute.show_output("enblend", args)
		if not rc == 0:
			print
			print
			print
			print 'Failed to blend'
			print 'rc: %d' % rc
			print args
			raise BlenderFailed('failed to remap')
Esempio n. 2
0
	def remap(self):
		project = self.pto_project.copy()
		old_files = get_nona_files(self.output_prefix, len(self.pto_project.get_image_lines()))
		# For my purposes right now I think this will always be 0
		if len(old_files) != 0:
			print old_files
			raise RemapperFailed('Found some old files')
		
		args = list()
		args.append("-m")
		args.append(self.image_type)
		pl = project.get_panorama_line()
		crop_opt = ""
		if self.image_type == Remapper.TIFF_SINGLE:
			if self.output_cropped:
				# FIXME: this needs to go into the n argument in the file, not a CLI option
				#  p f0 w1000 h500 v120 n"TIFF_m c:LZW r:CROP"
				#args.append("r:CROP")
				#pl.set_variable("n", "TIFF_m %s ", self.compression_opt)
				# will be saved when we get the file name
				#pl.save()
				crop_opt = "r:CROP"
		pl.set_variable("n", "%s %s %s" % (self.image_type, crop_opt, self.compression_opt))
		args.append("-verbose")
		args.append("-z")
		args.append("LZW")
		#args.append("-g")
		args.append("-o")
		args.append(self.output_prefix)
		args.append(project.get_a_file_name())
		#(rc, output) = Execute.with_output("nona", args)
		rc = Execute.show_output("nona", args)
		if not rc == 0:
			print
			print
			print
			print 'Failed to remap'
			#print output
			raise RemapperFailed('failed to remap')
		#project.reopen()
		if self.image_type == Remapper.TIFF_MULTILAYER:
			self.output_files = [self.output_prefix + '.tif']
		elif self.image_type == Remapper.TIFF_SINGLE:
			self.output_files = list()
			# This algorithm breaks down once you start doing cropping
			if 0:
				# The images shouldn't change, use the old loaded project
				for i in range(len(self.pto_project.get_image_lines())):
					fn = '%s%04d.tif' % (self.output_prefix, i)
					print 'Think we generated file %s' % fn
					if not os.path.exists(fn):
						raise RemapperFailed('Missing output file %s' % fn)
					self.output_files.append(fn)
			new_files = get_nona_files(self.output_prefix, len(self.pto_project.get_image_lines()))
			self.output_files = new_files.difference(old_files)
			print 'Think nona just generated files (%d new - %d old = %d delta):' % (len(new_files), len(old_files), len(self.output_files))
			# it may be a set but lists have advantages trying to trace whats happening
			self.output_files = sorted(list(self.output_files))
			if 0:
				for f in self.output_files:
					print '  %s' % f
		else:
			raise RemapperFailed('bad image type')
Esempio n. 3
0
	def run(self):
		'''
		The base Hugin project seems to work if you take out a few things:
		Eb1 Eev0 Er1 Ra0 Rb0 Rc0 Rd0 Re0 Va1 Vb0 Vc0 Vd0 Vx-0 Vy-0
		So say generate a project file with all of those replaced
		
		In particular we will generate new i lines
		To keep our original object intact we will instead do a diff and replace the optimized things on the old project
		
		
		Output is merged into the original file and starts after a line with a single *
		Even Hugin wpon't respect this optimization if loaded in as is
		Gives lines out like this
		
		o f0 r0 p0 y0 v51 a0.000000 b0.000000 c0.000000 g-0.000000 t-0.000000 d-0.000000 e-0.000000 u10 -buf 
		These are the lines we care about
		
		C i0 c0  x3996.61 y607.045 X3996.62 Y607.039  D1.4009 Dx-1.15133 Dy0.798094
		Where D is the magnitutde of the distance and x and y are the x and y differences to fitted solution
		
		There are several other lines that are just the repeats of previous lines
		'''
		bench = Benchmark()
		
		# The following will assume all of the images have the same size
		self.verify_images()
		
		# Copy project so we can trash it
		project = self.project.to_ptoptimizer()
		prepare_pto(project, self.reoptimize)
		
		pre_run_text = project.get_text()
		if 0:
			print
			print
			print 'PT optimizer project:'
			print pre_run_text
			print
			print
				
		
		# "PToptimizer out.pto"
		args = list()
		args.append(project.get_a_file_name())
		#project.save()
		rc = Execute.show_output("PToptimizer", args)
		if not rc == 0:
			print
			print
			print 'Failed rc: %d' % rc
			print 'Failed project:'
			print pre_run_text
			print
			print
			raise Exception('failed position optimization')
		# API assumes that projects don't change under us
		project.reopen()
		
		'''
		Line looks like this
		# final rms error 24.0394 units
		'''
		rms_error = None
		for l in project.get_comment_lines():
			if l.find('final rms error') >= 00:
				rms_error = float(l.split()[4])
				break
		print 'Optimize: RMS error of %f' % rms_error
		# Filter out gross optimization problems
		if self.rms_error_threshold and rms_error > self.rms_error_threshold:
			raise Exception("Max RMS error threshold %f but got %f" % (self.rms_error_threshold, rms_error))
		
		if self.debug:
			print 'Parsed: %s' % str(project.parsed)

		if self.debug:
			print
			print
			print
			print 'Optimized project:'
			print project
		 	#sys.exit(1)
	 	print 'Optimized project parsed: %d' % project.parsed

		print 'Merging project...'
		merge_pto(project, self.project)
		if self.debug:
			print self.project
		
		bench.stop()
		print 'Optimized project in %s' % bench
		
		# These are beyond this scope
		# Move them somewhere else if we want them
		if 0:
			# The following will assume all of the images have the same size
			self.verify_images()
		
			# Final dimensions are determined by field of view and width
			# Calculate optimial dimensions
			self.calc_dimensions()
		
			print 'Centering project...'
			self.center_project()
		
			'''
			WARNING WARNING WARNING
			The panotools model is too advanced for what I'm doing right now
			The image correction has its merits but is mostly getting in the way to distort images
		
			Therefore, I'd like to complete this to understand the intended use but I suspect its not a good idea
			and I could do my own nona style program much better
			The only downside is that if / when I start doing lens model corrections I'll have to rethink this a little
		
			Actually, a lot of these problems go away if I trim to a single tile
			I can use the same FOV as the source image or something similar
			'''
			print 'Calculating optimial field of view to match desired size...'
			self.calc_fov()