~ubuntu-branches/ubuntu/trusty/hugin/trusty-proposed

« back to all changes in this revision

Viewing changes to utils/mergepto

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2011-01-06 14:28:24 UTC
  • mfrom: (1.1.9 upstream) (0.1.21 experimental)
  • Revision ID: james.westby@ubuntu.com-20110106142824-zn9lxylg5z44dynn
* Drop Cyril Brulebois from Uploaders. Thank you very much for your work.
* Bump package version. (rc3 was re-released as 2010.4.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -w
2
 
# Merge two or more pto files - Chris
3
 
# It's useful to make panoramas by more image rows, 
4
 
# if control points for each row were generated by autopano.
5
 
# After the merging do not forget to make control points between
6
 
# the rows...
7
 
 
8
 
use strict;
9
 
 
10
 
if (@ARGV < 1 ) {
11
 
 die <<EOF;
12
 
Usage: mergepto [-o merged.pto ] row1.pto row2.pto [ row3.pto ... ]
13
 
EOF
14
 
}
15
 
 
16
 
my $outname="merged.pto";
17
 
my @ptos;    # pto file names
18
 
my @clines;  # control point lines
19
 
my @ilines;  # input image lines
20
 
my $pline;   # save the p line
21
 
my $mline;   # save the m line
22
 
my $first_i_line=1; # first i line should not be altered
23
 
my $image_offset=0; # value to increment the image numbers in c lines
24
 
 
25
 
while ($_=shift(@ARGV))
26
 
{ if (/-o/) { $outname=shift; }
27
 
  else { push(@ptos,$_); } 
28
 
}
29
 
 
30
 
if ( @ptos < 2 ) { die "Please give at least two pto files\n"; }
31
 
open(OUT,">$outname") || die "Could not open $outname for writing\n";
32
 
print "Merging " . @ptos . " pto files to $outname...\n";
33
 
 
34
 
# read input files...
35
 
for(my $f=0;$f < @ptos;$f++) 
36
 
{ # print "Processing " . ($f+1) . ":$ptos[$f]...\n"; 
37
 
 
38
 
  open(IN,"<$ptos[$f]") || die "Could not open $ptos[$f]\n";
39
 
 
40
 
  my $images_in_pto=0;
41
 
 
42
 
  while(<IN>)
43
 
  {
44
 
    $pline=$_ if (/^p / && $f eq 0);
45
 
    $mline=$_ if (/^m / && $f eq 0);
46
 
 
47
 
    if (/^i /) 
48
 
    { $images_in_pto++;
49
 
      if ($first_i_line) { chop; push(@ilines,$_); undef $first_i_line; }
50
 
      else {
51
 
        my @i=split();
52
 
        # set the same lens parameters as by the first image
53
 
        #$i[4]="a=0";
54
 
        #$i[5]="b=0";
55
 
        #$i[6]="c=0";
56
 
        #$i[11]="v=0";
57
 
        push(@ilines,join(' ',@i));
58
 
        }  
59
 
    }
60
 
 
61
 
    if (/^c /)
62
 
    { chop;
63
 
      my ($img1)= / n(\d+) /;
64
 
      my ($img2)= / N(\d+) /;
65
 
      $img1+=$image_offset;
66
 
      $img2+=$image_offset;
67
 
      s/ n(\d+) / n$img1 /;
68
 
      s/ N(\d+) / N$img2 /;
69
 
      push(@clines,$_);
70
 
    }
71
 
  }
72
 
  close(IN);
73
 
 
74
 
  # image number offset for the next file
75
 
  $image_offset+=$images_in_pto;
76
 
}
77
 
 
78
 
# write output...
79
 
print OUT "# merged pto files\n\n$pline$mline\n";
80
 
foreach my $il (@ilines) { print OUT $il . "\n"; }
81
 
print OUT "\n# control points\n";
82
 
foreach my $cl (@clines) { print OUT $cl . "\n"; }
83
 
close(OUT);
84
 
 
85
 
print "$outname has " . @ilines . " images and " . @clines . " control points.\n";
86