예제 #1
0
	def run(self):
		'''
		Phase 1: remap the relevant source image areas onto a canvas
		
		Note that nona will load ALL of the images (one at a time)
		but will only generate output for those that matter
		Each one takes a noticible amount of time but its relatively small compared to the time spent actually mapping images
		'''
		print
		print 'Supertile phase 1: remapping (nona)'
		if self.out.find('.') < 0:
			raise Exception('Require image extension')
		# Hugin likes to use the base filename as the intermediates, lets do the sames
		out_name_base = self.out[0:self.out.find('.')].split('/')[-1]
		print "out name: %s, base: %s" % (self.out, out_name_base)
		#ssadf
		if out_name_base is None or len(out_name_base) == 0 or out_name_base == '.' or out_name_base == '..':
			raise Exception('Bad output file base "%s"' % str(out_name_base))

		# Scope of these files is only here
		# We only produce the single output file, not the intermediates
		managed_temp_dir = ManagedTempDir.get()
		# without the slash they go into the parent directory with that prefix
		out_name_prefix = managed_temp_dir.file_name + "/"
		
		pto = self.pto.copy()
		print 'Making absolute'
		pto.make_absolute()
		
		print 'Cropping...'
		#sys.exit(1)
		pl = pto.get_panorama_line()
		# It is fine to go out of bounds, it will be black filled
		#pl.set_bounds(x, min(x + self.tw(), pto.right()), y, min(y + self.th(), pto.bottom()))
		pl.set_crop(self.bounds)
		remapper = Remapper(pto, out_name_prefix)
		remapper.remap()
		
		'''
		Phase 2: blend the remapped images into an output image
		'''
		print
		print 'Supertile phase 2: blending (enblend)'
		blender = Blender(remapper.get_output_files(), self.out)
		blender.run()
		# We are done with these files, they should be nuked
		if not config.keep_temp_files():
			for f in remapper.get_output_files():
				os.remove(f)
		
		print 'Supertile ready!'
예제 #2
0
	def generate_core(self, image_file_names):
		command = "autopanoaj"
		args = list()
		final_project_file = ManagedTempFile.get(None, ".pto")
		temp_dir = ManagedTempDir.get()
		
		# default is .oto
		args.append("/project:hugin")
		# Use image args instead of dir
		
		# Images
		image_links = dict()
		for image_file_name in image_file_names:
			# args.append(image_file_name.replace("/tmp/", "Z:\\tmp\\"))
			image_file_name = os.path.realpath(image_file_name)

			link_file_name = os.path.join(temp_dir.file_name, os.path.basename(image_file_name))
			print 'Linking %s -> %s' % (link_file_name, image_file_name)
			os.symlink(image_file_name, link_file_name)

		#sys.exit(1)
		# go go go
		(rc, output) = Execute.with_output(command, args, temp_dir.file_name)
		print 'Finished control point pair execution'
		if not rc == 0:
			print
			print
			print
			print 'output:\n%s' % output

			if output.find('This application has requested the Runtime to terminate it in an unusual way'):
				print 'WARNING: skipping crash'
				return None
			
			raise Exception('Bad rc: %d' % rc)
		
		'''
		Doesn't like the match:
		PICTURE PAIRS VALIDATION 
		  Pair (  0,  1)
			Ransac (In : 21, Out : 4, Residu : 4.43799)
			REMOVED
		  Timing : 583.7 us
		'''
		if output.find('REMOVED') >= 0:
			print 'WARNING: RANSAC invalidated control points'
			return None
		
		output_file_name = os.path.join(temp_dir.file_name, "panorama0.pto")
		
		# This happens occassionally, not sure why
		if not os.path.exists(output_file_name):
			print 'WARNING: missing output pto file!'
			return None
		
		# We return PTO object, not string
		# Ditch the gen file because its unreliable
		shutil.move(output_file_name, final_project_file.file_name)
		f = open(final_project_file.file_name, 'r')
		project_text = f.read()
		# Under WINE, do fixup
		# #-imgfile 2816 704 "Z:\tmp\pr0ntools_471477ADA1679A2E\pr0ntools_3CD1C0B1BB218E40.jpg"
		project_text = project_text.replace('Z:\\', '/').replace('\\', '/')
		for image_file_name in image_file_names:
			link_file_name = os.path.join(temp_dir.file_name, os.path.basename(image_file_name))
			print 'Replacing %s -> %s' % (link_file_name, image_file_name)
			project_text = project_text.replace(link_file_name, image_file_name)

		if False:
			print
			print 'Raw control point project (after symbolic link and WINE file name substitution)'
			print
			print
			print project_text
			print
			print
			print
		#sys.exit(1)
		f.close()
		f = open(final_project_file.file_name, 'w')
		f.write(project_text)
		project = PTOProject.from_temp_file(final_project_file)
		return project