[bc9e24]: utils / mergepto  Maximize  Restore  History

Download this file

87 lines (71 with data), 2.2 kB

#!/usr/bin/perl -w
# Merge two or more pto files - Chris
# It's useful to make panoramas by more image rows, 
# if control points for each row were generated by autopano.
# After the merging do not forget to make control points between
# the rows...

use strict;

if (@ARGV < 1 ) {
 die <<EOF;
Usage: mergepto [-o merged.pto ] row1.pto row2.pto [ row3.pto ... ]
EOF
}

my $outname="merged.pto";
my @ptos;    # pto file names
my @clines;  # control point lines
my @ilines;  # input image lines
my $pline;   # save the p line
my $mline;   # save the m line
my $first_i_line=1; # first i line should not be altered
my $image_offset=0; # value to increment the image numbers in c lines

while ($_=shift(@ARGV))
{ if (/-o/) { $outname=shift; }
  else { push(@ptos,$_); } 
}

if ( @ptos < 2 ) { die "Please give at least two pto files\n"; }
open(OUT,">$outname") || die "Could not open $outname for writing\n";
print "Merging " . @ptos . " pto files to $outname...\n";

# read input files...
for(my $f=0;$f < @ptos;$f++) 
{ # print "Processing " . ($f+1) . ":$ptos[$f]...\n"; 

  open(IN,"<$ptos[$f]") || die "Could not open $ptos[$f]\n";
 
  my $images_in_pto=0;
 
  while(<IN>)
  {
    $pline=$_ if (/^p / && $f eq 0);
    $mline=$_ if (/^m / && $f eq 0);

    if (/^i /) 
    { $images_in_pto++;
      if ($first_i_line) { chop; push(@ilines,$_); undef $first_i_line; }
      else {
        my @i=split();
        # set the same lens parameters as by the first image
        #$i[4]="a=0";
        #$i[5]="b=0";
        #$i[6]="c=0";
        #$i[11]="v=0";
        push(@ilines,join(' ',@i));
        }  
    }

    if (/^c /)
    { chop;
      my ($img1)= / n(\d+) /;
      my ($img2)= / N(\d+) /;
      $img1+=$image_offset;
      $img2+=$image_offset;
      s/ n(\d+) / n$img1 /;
      s/ N(\d+) / N$img2 /;
      push(@clines,$_);
    }
  }
  close(IN);

  # image number offset for the next file
  $image_offset+=$images_in_pto;
}

# write output...
print OUT "# merged pto files\n\n$pline$mline\n";
foreach my $il (@ilines) { print OUT $il . "\n"; }
print OUT "\n# control points\n";
foreach my $cl (@clines) { print OUT $cl . "\n"; }
close(OUT);

print "$outname has " . @ilines . " images and " . @clines . " control points.\n";