def pto_unsub(src_prj, sub_image_files, deltas, sub_to_real):
    '''
    Transforms a sub-project back into original control point coordinate space using original file names
    Returns a new project file
    src_prj: base project that needs to be transformed
    sub_image_files: tuple specifying original project 0/1 positions
        needed to correctly apply deltas
    deltas: delta to apply to pair_project coordinates to bring back to target (original) project space
        0: x
        1: y
        images are relative to each other
        only has delta within relative image frame, not entire project canvas
    sub_to_real: map of project file names to target (original) project file names
        the output project must use these instead of the original names
    '''
    ret = PTOProject.from_simple()

    same_order = True
    # Copy/fix images
    print 'Order check'
    for i, src_il in enumerate(src_prj.get_image_lines()):
        # copy it
        dst_il = ImageLine(str(src_il), ret)
        # fix the name so that it can be merged
        dst_il.set_name(sub_to_real[src_il.get_name()])
        # add it
        ret.add_image_line(dst_il)
        same_order = same_order and sub_image_files[
            i].file_name == src_il.get_name()
        print '  %d: %s vs %s' % (i, sub_image_files[i].file_name,
                                  src_il.get_name())

    # Copy/shift control points
    # Should have been filtered out earlier
    if len(src_prj.get_control_point_lines()) == 0:
        raise Exception('No source control point lines')
    for src_cpl in src_prj.get_control_point_lines():
        # copy it
        dst_cpl = ControlPointLine(str(src_cpl), ret)
        # shift to original coordinate space
        if same_order:
            # normal adjustment
            dst_cpl.set_variable('x', src_cpl.get_variable('x') + deltas[0])
            dst_cpl.set_variable('y', src_cpl.get_variable('y') + deltas[1])
        else:
            # they got flipped
            dst_cpl.set_variable('X', src_cpl.get_variable('X') + deltas[0])
            dst_cpl.set_variable('Y', src_cpl.get_variable('Y') + deltas[1])
        # add it
        ret.add_control_point_line(dst_cpl)

    return ret
Example #2
0
def pto_unsub(src_prj, sub_image_files, deltas, sub_to_real):
    """
    Transforms a sub-project back into original control point coordinate space using original file names
    Returns a new project file
    src_prj: base project that needs to be transformed
    sub_image_files: tuple specifying original project 0/1 positions
        needed to correctly apply deltas
    deltas: delta to apply to pair_project coordinates to bring back to target (original) project space
        0: x
        1: y
        images are relative to each other
        only has delta within relative image frame, not entire project canvas
    sub_to_real: map of project file names to target (original) project file names
        the output project must use these instead of the original names
    """
    ret = PTOProject.from_simple()

    same_order = True
    # Copy/fix images
    print "Order check"
    for i, src_il in enumerate(src_prj.get_image_lines()):
        # copy it
        dst_il = ImageLine(str(src_il), ret)
        # fix the name so that it can be merged
        dst_il.set_name(sub_to_real[src_il.get_name()])
        # add it
        ret.add_image_line(dst_il)
        same_order = same_order and sub_image_files[i].file_name == src_il.get_name()
        print "  %d: %s vs %s" % (i, sub_image_files[i].file_name, src_il.get_name())

    # Copy/shift control points
    # Should have been filtered out earlier
    if len(src_prj.get_control_point_lines()) == 0:
        raise Exception("No source control point lines")
    for src_cpl in src_prj.get_control_point_lines():
        # copy it
        dst_cpl = ControlPointLine(str(src_cpl), ret)
        # shift to original coordinate space
        if same_order:
            # normal adjustment
            dst_cpl.set_variable("x", src_cpl.get_variable("x") + deltas[0])
            dst_cpl.set_variable("y", src_cpl.get_variable("y") + deltas[1])
        else:
            # they got flipped
            dst_cpl.set_variable("X", src_cpl.get_variable("X") + deltas[0])
            dst_cpl.set_variable("Y", src_cpl.get_variable("Y") + deltas[1])
        # add it
        ret.add_control_point_line(dst_cpl)

    return ret
Example #3
0
def ajpto2pto_text(pto_str, sub_image_0_file, sub_image_1_file, sub_image_0_x_delta, sub_image_0_y_delta, sub_to_real, load_images = True):
	'''Take in an old style autopanoaj project and return a .pto object'''

	# image index to subimage file name link (not symbolic link)
	index_to_sub_file_name = dict()
	imgfile_index = 0
	part_pair_index = 0
	
	ret = PTOProject.from_simple()
	
	#out = ''
	
	'''Convert .oto text (like from autopanoaj) to a .pto'''
	# Actually I think really is a .pto, just in a less common format
	for line in pto_str.split('\n'):
		if len(line) == 0:
			continue
		# This type of line is gen by autopano-sift-c
		elif line[0] == 'c':
			# c n0 N1 x1142.261719 y245.074757 X699.189408 Y426.042661 t0
		
			'''
			Okay def alphabetical issues
			# Not strictly related to this code, but close enough
			if not index_to_sub_file_name[0] == sub_image_0_file:
				print '0 index indicated file: %s, pair gen order expected %s' % (index_to_sub_file_name[0], sub_image_0_file)
				raise Exception('mismatch')
			if not index_to_sub_file_name[1] == sub_image_1_file:
				print '1 index indicated file: %s, pair gen order expected %s' % (index_to_sub_file_name[1], sub_image_1_file)
				raise Exception('mismatch')
			'''
		
			# Parse
			parts = line.split()
			if not parts[1] == 'n0':
				print parts[1]
				raise Exception('mismatch')
			if not parts[2] == 'N1':
				print parts[2]
				raise Exception('mismatch')
			
			x = float(parts[3][1:])								
			y = float(parts[4][1:])
			X = float(parts[5][1:])
			Y = float(parts[6][1:])

			#sub_image_1_x_end = image_1.width()
			#sub_image_1_y_end = image_1.height()

			# Adjust the image towards the upper left hand corner
			if index_to_sub_file_name[0] == sub_image_0_file.file_name:
				# normal adjustment
				x += sub_image_0_x_delta
				y += sub_image_0_y_delta
			elif index_to_sub_file_name[1] == sub_image_0_file.file_name:
				# they got flipped
				X += sub_image_0_x_delta
				Y += sub_image_0_y_delta
			else:
				print index_to_sub_file_name
				print 'index_to_sub_file_name[0]: %s' % repr(index_to_sub_file_name[0])
				print 'index_to_sub_file_name[1]: %s' % repr(index_to_sub_file_name[1])
				print 'sub_image_0_file: %s' % repr(sub_image_0_file)
				print 'sub_image_1_file: %s' % repr(sub_image_1_file)
				raise Exception("confused")

			# Write
			new_line = "c n0 N1 x%f y%f X%f Y%f t0" % (x, y, X, Y)
			#out += new_line + '\n'
			ret.add_control_point_line_by_text(new_line)
		# This type of line is generated by pto_merge
		elif line[0] == 'o':
			'''
			#-imgfile 1632 408 "/tmp/pr0ntools_6691335AD228382E.jpg"
			o f0 y+0.000000 r+0.000000 p+0.000000 u20 d0.000000 e0.000000 v70.000000 a0.000000 b0.000000 c0.000000
			to
			i w2816 h704 f0 a0 b-0.01 c0 d0 e0 p0 r0 v180 y0  u10 n"/tmp/pr0ntools_6691335AD228382E.jpg"
			'''
			new_line = ''
			new_line += 'i'
			# Deferred to end
			if 0:
				# panotools fails in very exciting ways if you don't set this
				new_line += ' w%d' % images[0].width()
				new_line += ' w%d' % images[0].height()
			# default FOV
			new_line += ' v51'
			
			orig_fn = index_to_sub_file_name[part_pair_index]
			new_fn = sub_to_real[orig_fn]
			print 'Replacing %s => %s' % (orig_fn, new_fn)
			new_line += ' n"%s"' % new_fn
			
			part_pair_index += 1
			print 'new line: %s' % new_line
			ret.add_image_line_by_text(new_line)
		# These lines are generated by autopanoaj
		# The comment line is literally part of the file format, some sort of bizarre encoding
		# #-imgfile 2816 704 "/tmp/pr0ntools_2D24DE9F6CC513E0/pr0ntools_6575AA69EA66B3C3.jpg"
		# o f0 y+0.000000 r+0.000000 p+0.000000 u20 d0.000000 e0.000000 v70.000000 a0.000000 b0.000000 c0.000000
		elif line.find('#-imgfile') == 0:
			# Replace pseudo file names with real ones
			new_line = line
			index_to_sub_file_name[imgfile_index] = line.split('"')[1]
			imgfile_index += 1
		elif line.find('#') == 0:
			pass
		else:
			#new_line = line
			print 'WARNING: discarding unknown line %s' % line
		#out += new_line + '\n'
	#else:
		#out += line + '\n'

	#ret = PTOProject.from_text(out)
	
	if load_images:
		print 'Fixing up image lines'
		fixup_image_dim(ret)
	
	return ret