Attached below is what I think is a working copy of the ptoscale Perl module.

If anyone has a chance can you test it out and let me know if you have any 
problems.
        It works in conjunction with and requires Bruno’s Panotools:: Script 
Perl module

> On Jul 11, 2016, at 3:22 AM, Bruno Postle <[email protected]> wrote:
> 

> On 11 July 2016 03:22:28 BST, Donald Johnston wrote:

> 

> >Following some examples in your code I wrote:

> 

> >> $i->{d} = int ($i->{d} *= $R if $i->{d} =~ /^[-0-9.]+$/);

> 
> Misplaced brackets, something like:
> 
> int ($i->{d} *= $R) if …

> 
> (writing on my phone, so excuse me for not typing the whole line!)

Thanks Bruno. I can see why the Perl compiler might have problems with an “if” 
statement as an argument for the “int” function.

> 

> >The first two lines seem to work but then I get an error (I think the

> >third line above is line 34)

> >

> >Also, if d, e, Vx, and Vy are pixel values why are you even doing the

> >match in those lines???

> 
> I have no idea, mistakes are always a possibility.

Never “mistakes”; best to refer to them as “features”.  I’ve just left them in 
the modified code for ptoscale.

> 
> -- 
> Bruno
> 

Some notes on the code.
I had to move the code that handles the crop (S) from the image lines to the 
$p->Panorama line. Is this something you would have to do with your ptohalf and 
ptodouble modules?
Is there a web page that details the format of the lines within a .pto file? 
I’ve done a search but haven’t been able to find anything.
The int function doesn’t work well with floating point numbers so I turned it 
into more of a rounding function by adding 0.5 to the values before doing the 
integer. Sometimes what Perl might display as 4913 for example is actually 
4912.9999999999 in floating point and so int returns 4912.
I wrote an extensive help part for the module (I hope it is understandable).
To be quite honest I have no idea what some of the lines in the code do as this 
is my first attempt at Perl (Thanks for your help Bruno!!!)

One test I did (below) was because I had made the small trial .pto project at 
1600 pixels before I realized I’d want to scale back up to the large image size 
at 7360 pixels.

        /Applications/Panotools-Script-0.28/bin/ptoscale -s 7360/1600 -o 
scaled.pto trial.pto




THE CODE


> #!/usr/bin/perl
> use strict;
> use warnings;
> use Panotools::Script;
> use Getopt::Long;
> use Pod::Usage;
> 
> my $scale;
> my $path_output;
> my $help = 0;
> 
> GetOptions ('s|scale=s' => \$scale,
>             'o|output=s' => \$path_output,
>             'h|help' => \$help);
> 
> pod2usage (-verbose => 2) if $help;
> 
> my $path_pto = shift || pod2usage;
> die "Can't find $path_pto" unless -e $path_pto;
> 
> my $R = 1;
> if ($scale =~ /\//)
> {
>     my @Ratio = split ('/', $scale);
>     $R = $Ratio[0] / $Ratio[1];
> } else {
>     $R=$scale
> }
> 
> my $p = new Panotools::Script;
> $p->Read ($path_pto);
> 
> $p->Panorama->{w} = int (0.5 + ($p->Panorama->{w} *= $R));
> $p->Panorama->{h} = int (0.5 + ($p->Panorama->{h} *= $R));
> if (defined $p->Panorama->{S})
> {
>     my @S = split (',', $p->Panorama->{S});
>     @S = map {int (0.5 + ($_ * $R))} @S;
>     $p->Panorama->{S} = join ',', @S;
> }
> 
> for my $i (@{$p->Image})
> {
>     $i->{w} = int (0.5 + ($i->{w} *= $R));
>     $i->{h} = int (0.5 + ($i->{h} *= $R));
>     $i->{d} = int (0.5 + ($i->{d} *= $R)) if $i->{d} =~ /^[-0-9.]+$/;
>     $i->{e} = int (0.5 + ($i->{e} *= $R)) if $i->{e} =~ /^[-0-9.]+$/;
>     $i->{Vx} = int (0.5 + ($i->{Vx} *= $R)) if $i->{Vx} =~ /^[-0-9.]+$/;
>     $i->{Vy} = int (0.5 + ($i->{Vy} *= $R)) if $i->{Vy} =~ /^[-0-9.]+$/;
> }
> 
> for my $c (@{$p->Control})
> {
>     $c->{x} *= $R;
>     $c->{y} *= $R;
>     $c->{X} *= $R;
>     $c->{Y} *= $R;
> }
> 
> for my $k (@{$p->Mask})
> {
>     my $string = $k->{p};
>     $string =~ s/"//g;
>     my @p = split (' ', $string);
>     @p = map {int (0.5 + ($_ * $R))} @p;
>     $k->{p} = '"'. (join ' ', @p) .'"';
> }
> 
> $p->Write ($path_output);
> 
> exit 0;
> 
> __END__
> 
> =head1 NAME
> 
> ptoscale - rescale a panorama project
> 
> =head1 SYNOPSIS
> 
> ptoscale [options] --output scaled.pto project.pto
> 
>  Options:
>   -s | --scale      Scale ratio (in the format n; or m/n where m = new side 
> length, n = old side length)
>   -o | --output     Filename of scaled project (can be the same as the input)
>   -h | --help       Outputs help documentation
> 
> =head1 DESCRIPTION
> 
> B<ptoscale> takes a hugin .pto project and scales all pixel dimensions by the 
> ratio given (--scale).  It is best to use a scale factor consisting of the 
> common divisors of the width and height of the image (in pixels).
> 
> For example: an image that is 3648x2736 has common divisors of 2, 2, 2, 2, 
> and 3. So a scale factor of 4, 6, or 8 would work (also 3648/912, 3648/608, 
> or 3648/456). Inverses and rationals work also: 0.5, 1.5, and 2/3 for example.
> 
> You will need to rescale the photos to match:
> 
>   mogrify -geometry {m/n}% *.JPG
> 
> Note, this tool is useful in conjunction with the L<ptodouble> and 
> L<ptohalve> tools which
> perform the specific scaling of 2 and 0.5 respectively.
> 
> =head1 TYPICAL WORKFLOW
> 
> 1. Create lower resolution copies of your image so you can experiment with 
> hugin settings (this will reduce computation time for testing). Use a 
> reduction amount similar to the scale factor covered above.
> 
>       for example: convert 3648x2736 images to 608x456 pixels (a scale factor 
> of 6)
> 
> 2. When you're please with the results use ptoscale to modify your pto file 
> to work with your original images.
> 
>       ptoscale -s 3648/608 -o scaled.pto trial.pto
> 
>       ptoscale -s 6 -o scaled.pto trial.pto
> 
> 
> =head1 LICENSE
> 
> This program is free software; you can redistribute it and/or
> modify it under the terms of the GNU General Public License
> as published by the Free Software Foundation; either version 2
> of the License, or (at your option) any later version.
> 
> =head1 SEE ALSO
> 
> L<http://hugin.sourceforge.net/>
> 
> L<ptodouble>
> 
> L<ptohalve>
> 
> =head1 AUTHOR
> 
> Donald Johnston; modified from Bruno Postle's ptodouble - July 2016.
> 
> =cut

-- 
A list of frequently asked questions is available at: 
http://wiki.panotools.org/Hugin_FAQ
--- 
You received this message because you are subscribed to the Google Groups 
"hugin and other free panoramic software" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/hugin-ptx/116DB435-249A-4D31-A4BA-79DE19C1A9CB%40accesscomm.ca.
For more options, visit https://groups.google.com/d/optout.

Reply via email to