| 1 | package Panotools::Script::Line::Image; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use Panotools::Script::Line; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Panotools::Matrix qw(matrix2rollpitchyaw rollpitchyaw2matrix multiply); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Math::Trig; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Math::Trig ':radial'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use vars qw /@ISA/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 10 | @ISA = qw /Panotools::Script::Line/; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 10 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Panotools::Script::Line::Image - Panotools input image | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | A single input image is described by an 'i' line | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | Basically the same format as an 'o' line. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | w1000 | ||||||||||||||||||||||||||||
| 29 | h500 nona requires the width and height of input images wheras PTStitcher/mender don't | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | f0 projection format, | ||||||||||||||||||||||||||||
| 32 | 0 - rectilinear (normal lenses) | ||||||||||||||||||||||||||||
| 33 | 1 - Panoramic (Scanning cameras like Noblex) | ||||||||||||||||||||||||||||
| 34 | 2 - Circular fisheye | ||||||||||||||||||||||||||||
| 35 | 3 - full-frame fisheye | ||||||||||||||||||||||||||||
| 36 | 4 - PSphere, equirectangular | ||||||||||||||||||||||||||||
| 37 | 7 - Mirror (a spherical mirror) | ||||||||||||||||||||||||||||
| 38 | 8 - Orthographic fisheye | ||||||||||||||||||||||||||||
| 39 | 10 - Stereographic fisheye | ||||||||||||||||||||||||||||
| 40 | 21 - Equisolid fisheye | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | v82 horizontal field of view of image (required) | ||||||||||||||||||||||||||||
| 43 | y0 yaw angle (required) | ||||||||||||||||||||||||||||
| 44 | p43 pitch angle (required) | ||||||||||||||||||||||||||||
| 45 | r0 roll angle (required) | ||||||||||||||||||||||||||||
| 46 | a,b,c lens correction coefficients (optional) | ||||||||||||||||||||||||||||
| 47 | (see http://www.fh-furtwangen.de/~dersch/barrel/barrel.html) | ||||||||||||||||||||||||||||
| 48 | d,e initial lens offset in pixels(defaults d0 e0, optional). | ||||||||||||||||||||||||||||
| 49 | Used to correct for offset from center of image | ||||||||||||||||||||||||||||
| 50 | d - horizontal offset, | ||||||||||||||||||||||||||||
| 51 | e - vertical offset | ||||||||||||||||||||||||||||
| 52 | g,t initial lens shear. Use to remove slight misalignment | ||||||||||||||||||||||||||||
| 53 | of the line scanner relative to the film transport | ||||||||||||||||||||||||||||
| 54 | g - horizontal shear | ||||||||||||||||||||||||||||
| 55 | t - vertical shear | ||||||||||||||||||||||||||||
| 56 | j stack number | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Eev exposure of image in EV (exposure values) | ||||||||||||||||||||||||||||
| 59 | Er white balance factor for red channel | ||||||||||||||||||||||||||||
| 60 | Eb white balance factor for blue channel | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Ra EMoR response model from the Computer Vision Lab at Columbia University | ||||||||||||||||||||||||||||
| 63 | Rb This models the camera response curve | ||||||||||||||||||||||||||||
| 64 | Rc | ||||||||||||||||||||||||||||
| 65 | Rd | ||||||||||||||||||||||||||||
| 66 | Re | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | TiX,TiY,TiZ Tilt on x axis, y axis, z axis | ||||||||||||||||||||||||||||
| 69 | TiS Scaling of field of view in the tilt transformation | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | TrX,TrY,TrZ Translation on x axis, y axis, z axis | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | Tpy,Tpp yaw and pitch of remapping plane for translation | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Te0,Te1,Te2,Te3 Test parameters | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Vm vignetting correction mode (default 0): | ||||||||||||||||||||||||||||
| 78 | 0: no vignetting correction | ||||||||||||||||||||||||||||
| 79 | 1: radial vignetting correction (see j,k,l,o options) | ||||||||||||||||||||||||||||
| 80 | 2: flatfield vignetting correction (see p option) | ||||||||||||||||||||||||||||
| 81 | 4: proportional correction: i_new = i / corr. | ||||||||||||||||||||||||||||
| 82 | This mode is recommended for use with linear data. | ||||||||||||||||||||||||||||
| 83 | If the input data is gamma corrected, try adding g2.2 | ||||||||||||||||||||||||||||
| 84 | to the m line. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | default is additive correction: i_new = i + corr | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Both radial and flatfield correction can be combined with the | ||||||||||||||||||||||||||||
| 89 | proportional correction by adding 4. | ||||||||||||||||||||||||||||
| 90 | Examples: i1 - radial polynomial correction by addition. | ||||||||||||||||||||||||||||
| 91 | The coefficients j,k,l,o must be specified. | ||||||||||||||||||||||||||||
| 92 | i5 - radial polynomial correction by division. | ||||||||||||||||||||||||||||
| 93 | The coefficients j,k,l,o must be specified. | ||||||||||||||||||||||||||||
| 94 | i6 - flatfield correction by division. | ||||||||||||||||||||||||||||
| 95 | The flatfield image should be specified with the p option | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Va,Vb,Vc,Vd vignetting correction coefficients. (defaults: 0,0,0,0) | ||||||||||||||||||||||||||||
| 98 | ( 0, 2, 4, 6 order polynomial coefficients): | ||||||||||||||||||||||||||||
| 99 | corr = ( i + j*r^2 + k*r^4 + l*r^6), where r is the distance from the image center | ||||||||||||||||||||||||||||
| 100 | The corrected pixel value is calculated with: i_new = i_old + corr | ||||||||||||||||||||||||||||
| 101 | if additive correction is used (default) | ||||||||||||||||||||||||||||
| 102 | for proportional correction (h5): i_new = i_old / corr; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Vx,Vy radial vignetting correction offset in pixels (defaults q0 w0, optional). | ||||||||||||||||||||||||||||
| 105 | Used to correct for offset from center of image | ||||||||||||||||||||||||||||
| 106 | Vx - horizontal offset | ||||||||||||||||||||||||||||
| 107 | Vy - vertical offset | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | S100,600,100,800 Selection(l,r,t,b), Only pixels inside the rectangle will be used for conversion. | ||||||||||||||||||||||||||||
| 110 | Original image size is used for all image parameters | ||||||||||||||||||||||||||||
| 111 | (e.g. field-of-view) refer to the original image. | ||||||||||||||||||||||||||||
| 112 | Selection can be outside image dimension. | ||||||||||||||||||||||||||||
| 113 | The selection will be circular for circular fisheye images, and | ||||||||||||||||||||||||||||
| 114 | rectangular for all other projection formats | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | nName file name of the input image. | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | i f2 r0 p0 y0 v183 a0 b-0.1 c0 S100,600,100,800 n"photo1.jpg" | ||||||||||||||||||||||||||||
| 119 | i f2 r0 p0 y180 v183 a0 b-0.1 c0 S100,600,100,800 n"photo1.jpg" | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | sub _defaults | ||||||||||||||||||||||||||||
| 124 | 51 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_defaults: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 125 | 51 | my $self = shift; | |||||||||||||||||||||||||||
| 126 | 51 | %{$self} = (a => 0, b => 0, c => 0, d => 0, e => 0, r => 0, p => 0, y => 0); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 103 | ▶ | sub _valid { return '^([abcdefghjnprtvwy]|[SCXYZ]|K[0-2][ab]|V[abcdfmxy]|Eev|E[rb]|Tp[yp]|Te[0123]|Tr[XYZ]|Ti[XYZS]|R[abcde])(.*)' } | ||||||||||||||||||||||||||
|
Subroutine
_valid: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub _valid_ptoptimizer { return '^([abcdefghnprtvwySC]|Tp[yp]|Te[0123]|Tr[XYZ]|Ti[XYZS])(.*)' } | ||||||||||||||||||||||||||
|
Subroutine
_valid_ptoptimizer: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub _sanitise_ptoptimizer | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_sanitise_ptoptimizer: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 136 | 0 | my $valid = $self->_valid_ptoptimizer; | |||||||||||||||||||||||||||
| 137 | 0 | for my $key (keys %{$self}) | |||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 0 | ▶ | delete $self->{$key} unless (grep /$valid/, $key); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | sub Identifier | ||||||||||||||||||||||||||||
| 144 | 23 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Identifier: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 23 | my $self = shift; | |||||||||||||||||||||||||||
| 146 | 23 | return "i"; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub Assemble | ||||||||||||||||||||||||||||
| 150 | 38 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Assemble: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 151 | 38 | my $self = shift; | |||||||||||||||||||||||||||
| 152 | 38 | ▶ | my $vector = shift || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 153 | 38 | $self->_sanitise; | |||||||||||||||||||||||||||
| 154 | 38 | my @tokens; | |||||||||||||||||||||||||||
| 155 | 38 | for my $entry (sort keys %{$self}) | |||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||
| 157 | 714 | my $value = $self->{$entry}; | |||||||||||||||||||||||||||
| 158 | 714 | ▶ | $value = _prepend ($vector, $value) if ($entry eq 'n'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 714 | push @tokens, $entry . $value; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | 38 | ▶ | return (join ' ', ($self->Identifier, @tokens)) ."\n" if (@tokens); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | return ''; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =pod | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Rotate transform the image, angles in degrees: | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | $i->Transform ($roll, $pitch, $yaw); | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | sub Transform | ||||||||||||||||||||||||||||
| 174 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Transform: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 175 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 176 | 7 | my ($roll, $pitch, $yaw) = @_; | |||||||||||||||||||||||||||
| 177 | 7 | my @transform_rpy = map (deg2rad ($_), ($roll, $pitch, $yaw)); | |||||||||||||||||||||||||||
| 178 | 7 | my $transform_matrix = rollpitchyaw2matrix (@transform_rpy); | |||||||||||||||||||||||||||
| 179 | 7 | my @rpy = map (deg2rad ($_), ($self->r, $self->p, $self->y)); | |||||||||||||||||||||||||||
| 180 | 7 | my $matrix = rollpitchyaw2matrix (@rpy); | |||||||||||||||||||||||||||
| 181 | 7 | my $result = multiply ($transform_matrix, $matrix); | |||||||||||||||||||||||||||
| 182 | 7 | my ($r, $p, $y) = map (rad2deg ($_), matrix2rollpitchyaw ($result)); | |||||||||||||||||||||||||||
| 183 | 7 | ▶ | $self->{r} = $r unless $self->{r} =~ /=/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 7 | ▶ | $self->{p} = $p unless $self->{p} =~ /=/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 7 | ▶ | $self->{y} = $y unless $self->{y} =~ /=/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | sub _prepend | ||||||||||||||||||||||||||||
| 189 | 38 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_prepend: called CC=3 SCAR=14.7
| |||||||||||||||||||||||||||||
| 190 | 38 | my $vector = shift; | |||||||||||||||||||||||||||
| 191 | 38 | my $name = shift; | |||||||||||||||||||||||||||
| 192 | 38 | ▶ | return $name unless $vector; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | $name =~ s/^"//; | |||||||||||||||||||||||||||
| 194 | 0 | $name =~ s/"$//; | |||||||||||||||||||||||||||
| 195 | 10 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | unless (File::Spec->file_name_is_absolute ($name)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||
| 198 | 0 | $name = File::Spec->catfile ($vector, $name); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | 0 | return "\"$name\""; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | sub Report | ||||||||||||||||||||||||||||
| 204 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Report: called CC=21 SCAR=34.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 205 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 206 | 1 | my @report; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 1 | my $format = 'UNKNOWN'; | |||||||||||||||||||||||||||
| 209 | 1 | ▶ | $format = "Rectilinear" if $self->{f} == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 1 | ▶ | $format = "Cylindrical" if $self->{f} == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 1 | ▶ | $format = "Circular Fisheye" if $self->{f} == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 1 | ▶ | $format = "Full-frame Fisheye" if $self->{f} == 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 1 | ▶ | $format = "Equirectangular" if $self->{f} == 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 1 | ▶ | $format = "Mirror (a spherical mirror)" if $self->{f} == 7; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 1 | ▶ | $format = "Orthographic fisheye" if $self->{f} == 8; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 1 | ▶ | $format = "Stereographic fisheye" if $self->{f} == 10; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 1 | ▶ | $format = "Equisolid fisheye" if $self->{f} == 21; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 1 | push @report, ['Dimensions', $self->{w} .'x'. $self->{h}]; | |||||||||||||||||||||||||||
| 220 | 1 | push @report, ['Megapixels', int ($self->{w} * $self->{h} / 1024 / 1024 * 10) / 10]; | |||||||||||||||||||||||||||
| 221 | 1 | push @report, ['Format', $format]; | |||||||||||||||||||||||||||
| 222 | 1 | push @report, ['Horizontal Field of View', $self->{v}]; | |||||||||||||||||||||||||||
| 223 | 1 | push @report, ['Roll Pitch Yaw', $self->{r} .','. $self->{p} .','. $self->{y}]; | |||||||||||||||||||||||||||
| 224 | 1 | ▶ | push @report, ['Tilt', $self->{TiX} .','. $self->{TiY} .','. $self->{TiZ} .','. $self->{TiS}] if defined $self->{TiS}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 1 | ▶ | push @report, ['XYZ transform', $self->{TrX} .','. $self->{TrY} .','. $self->{TrZ}] if defined $self->{TrX}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 1 | ▶ | push @report, ['Lens distortion', $self->{a} .','. $self->{b} .','. $self->{c}] if defined $self->{a}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 1 | ▶ | push @report, ['Image centre', $self->{d} .','. $self->{e}] if defined $self->{d}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 1 | ▶ | push @report, ['Image shear', $self->{g} .','. $self->{t}] if defined $self->{g}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 1 | ▶ | push @report, ['Exposure Value', $self->{Eev}] if defined $self->{Eev}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 1 | ▶ | push @report, ['Red Blue colour balance', $self->{Er} .','. $self->{Eb}] if defined $self->{Er}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 1 | ▶ | push @report, ['EMOR parameters', $self->{Ra} .','. $self->{Rb} .','. $self->{Rc} .','. $self->{Rd} .','. $self->{Re}] if defined $self->{Ra}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 1 | ▶ | push @report, ['Vignetting parameters', $self->{Va} .','. $self->{Vb} .','. $self->{Vc} .','. $self->{Vd}] if defined $self->{Va}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 1 | ▶ | push @report, ['Vignetting centre', $self->{Vx} .','. $self->{Vy}] if defined $self->{Vx}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 1 | ▶ | push @report, ['Selection area', $self->{S}] if defined $self->{S}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 1 | push @report, ['File name', $self->{n}]; | |||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 1 | [@report]; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | sub W2 | ||||||||||||||||||||||||||||
| 241 | 15 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
W2: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 242 | 15 | my $self = shift; | |||||||||||||||||||||||||||
| 243 | 15 | ▶ | return ($self->{w} / 2) if ($self->{w} < $self->{h}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 8 | return ($self->{h} / 2); | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | =pod | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | Each image attribute (v, a, b, c etc...) can be read like so: | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | $fov = $i->v; | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | Note that this will return either the value (56.7) or a reference to another | ||||||||||||||||||||||||||||
| 254 | image (=0). If you supply a Panotools::Script object as a parameter then the | ||||||||||||||||||||||||||||
| 255 | reference will be resolved and you will always get the value: | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | $fov = $i->v ($pto); | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =cut | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 262 | 274 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 263 | 274 | my $self = shift; | |||||||||||||||||||||||||||
| 264 | 274 | my $pto = shift; | |||||||||||||||||||||||||||
| 265 | 274 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||
| 266 | 274 | $name =~ s/.*://; | |||||||||||||||||||||||||||
| 267 | 274 | ▶ | return undef unless defined $self->{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 194 | ▶ | if ($self->{$name} =~ /^=([0-9]+)$/ and defined $pto) {return $pto->Image->[$1]->{$name}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{$name} =~ /^=([0-9]+)$/ and defined $pto
MC/DC50%1/2
$self->{$name} =~ /^=([0-9]+)$/ and defined $pto
$self->{$name} =~ /^=([0-9]+)$/
defined $pto
Truth table66%2/3
A and B
A= $self->{$name} =~ /^=([0-9]+)$/B= defined $pto
| |||||||||||||||||||||||||||||
| 269 | 167 | return $self->{$name}; | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =pod | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | Get the absolute path to the image file | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | $i->Path ('/path/to/project.pto'); | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | If a .pto project isn't specified then paths are assumed to be relatve to cwd | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =cut | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | sub Path | ||||||||||||||||||||||||||||
| 283 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Path: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 284 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 285 | 0 | my $path_pto = shift; | |||||||||||||||||||||||||||
| 286 | 0 | my $name = $self->{n}; | |||||||||||||||||||||||||||
| 287 | 0 | $name =~ s/^"(.*)"$/$1/; | |||||||||||||||||||||||||||
| 288 | 0 | ▶ | return $name if File::Spec->file_name_is_absolute ($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | ▶ | return File::Spec->rel2abs ($name) unless defined $path_pto; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 0 | my ($v, $d, $f) = File::Spec->splitpath ($path_pto); | |||||||||||||||||||||||||||
| 291 | 0 | my $base = File::Spec->catpath ($v, $d, ''); | |||||||||||||||||||||||||||
| 292 | 0 | return File::Spec->rel2abs ($name, $base); | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | # copied from libpano12 math.c inverse polynomial using Newton's method | ||||||||||||||||||||||||||||
| 296 | sub _inv_radial | ||||||||||||||||||||||||||||
| 297 | 13 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_inv_radial: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 298 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 299 | 13 | my $pto = shift; | |||||||||||||||||||||||||||
| 300 | 13 | my $dest = shift; | |||||||||||||||||||||||||||
| 301 | 13 | my $a = $self->a ($pto); | |||||||||||||||||||||||||||
| 302 | 13 | my $b = $self->b ($pto); | |||||||||||||||||||||||||||
| 303 | 13 | my $c = $self->c ($pto); | |||||||||||||||||||||||||||
| 304 | 13 | my $d = 1 - $a - $b - $c; | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 13 | my $iter = 0; | |||||||||||||||||||||||||||
| 307 | 13 | my $MAXITER = 100; | |||||||||||||||||||||||||||
| 308 | 13 | my $R_EPS = 0.000001; | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 13 | my $rd = (sqrt ($dest->[0] * $dest->[0] + $dest->[1] * $dest->[1])) / $self->W2; | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 13 | ▶ | return [0, 0] if $rd == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 7 | my $rs = $rd; | |||||||||||||||||||||||||||
| 315 | 7 | my $f = ((($a * $rs + $b) * $rs + $c) * $rs + $d) * $rs; | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 7 | ▶ | while (abs ($f - $rd) > $R_EPS && $iter < $MAXITER) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
abs $f - $rd > $R_EPS and $iter < $MAXITER
MC/DC50%1/2
abs $f - $rd > $R_EPS and $iter < $MAXITER
abs $f - $rd > $R_EPS
$iter < $MAXITER
Truth table66%2/3
A and B
A= abs $f - $rd > $R_EPSB= $iter < $MAXITER
| |||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||
| 319 | 4 | $rs = $rs - ($f - $rd) / (((4 * $a * $rs + 3 * $b) * $rs + 2 * $c) * $rs + $d); | |||||||||||||||||||||||||||
| 320 | 4 | $f = ((($a * $rs + $b) * $rs + $c) * $rs + $d) * $rs; | |||||||||||||||||||||||||||
| 321 | 4 | $iter++; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 7 | my $scale = $rs / $rd; | |||||||||||||||||||||||||||
| 325 | # print "scale = $scale iter = $iter\n"; | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 7 | return [$dest->[0] * $scale, $dest->[1] * $scale]; | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | sub _radial | ||||||||||||||||||||||||||||
| 331 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_radial: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 332 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 333 | 1 | my $pto = shift; | |||||||||||||||||||||||||||
| 334 | 1 | my $dest = shift; | |||||||||||||||||||||||||||
| 335 | 1 | my $a = $self->a ($pto); | |||||||||||||||||||||||||||
| 336 | 1 | my $b = $self->b ($pto); | |||||||||||||||||||||||||||
| 337 | 1 | my $c = $self->c ($pto); | |||||||||||||||||||||||||||
| 338 | 1 | my $d = 1 - $a - $b - $c; | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 1 | my $r = (sqrt ($dest->[0] * $dest->[0] + $dest->[1] * $dest->[1])) / $self->W2; | |||||||||||||||||||||||||||
| 341 | 1 | my $scale = (($a * $r + $b) * $r + $c) * $r + $d; | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 1 | return [$dest->[0] * $scale, $dest->[1] * $scale]; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | =pod | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | For any given coordinate in this image (top left is 0,0), calculate an x,y,z | ||||||||||||||||||||||||||||
| 349 | cartesian coordinate, accounting for lens distortion, projection and rotation. | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | $coor = $i->To_Cartesian ($pto, [23,45]); | ||||||||||||||||||||||||||||
| 352 | ($x, $y, $z) = @{$coor}; | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | =cut | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | sub To_Cartesian | ||||||||||||||||||||||||||||
| 357 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
To_Cartesian: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 358 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 359 | 12 | my $pto = shift; | |||||||||||||||||||||||||||
| 360 | 12 | my $pix = shift; | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 12 | $pix->[0] = ($self->{w}/2) - $pix->[0] + $self->d ($pto); | |||||||||||||||||||||||||||
| 363 | 12 | $pix->[1] = ($self->{h}/2) - $pix->[1] + $self->e ($pto); | |||||||||||||||||||||||||||
| 364 | 12 | $pix = $self->_inv_radial ($pto, $pix); | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | # FIXME returns false value for cylindrical and equirectangular images | ||||||||||||||||||||||||||||
| 367 | 12 | my $point = [[1],[0],[0]]; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 12 | ▶ | if ($self->{f} == 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||
| 371 | 12 | my $rad = ($self->{w}/2) / tan (deg2rad ($self->v ($pto)) / 2); | |||||||||||||||||||||||||||
| 372 | 12 | $point = [[$rad], [$pix->[0]], [$pix->[1]]]; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | 12 | ▶ | if ($self->{f} == 2 or $self->{f} == 3) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"f"} == 2 or $self->{"f"} == 3
MC/DC0%0/2
$self->{"f"} == 2 or $self->{"f"} == 3
$self->{"f"} == 2
$self->{"f"} == 3
Truth table33%1/3
A or B
A= $self->{"f"} == 2B= $self->{"f"} == 3
| |||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||
| 376 | 0 | my ($rho, $theta, $z) = cartesian_to_cylindrical ($pix->[1], $pix->[0], 1); | |||||||||||||||||||||||||||
| 377 | 0 | my $phi = $rho * deg2rad ($self->v ($pto)) / $self->{w}; | |||||||||||||||||||||||||||
| 378 | 0 | $rho = $z; | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 0 | ($point->[2]->[0], | |||||||||||||||||||||||||||
| 381 | $point->[1]->[0], | ||||||||||||||||||||||||||||
| 382 | $point->[0]->[0]) | ||||||||||||||||||||||||||||
| 383 | = spherical_to_cartesian ($rho, $theta, $phi); | ||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 12 | my $matrix = rollpitchyaw2matrix | |||||||||||||||||||||||||||
| 387 | (deg2rad ($self->r), deg2rad ($self->p), deg2rad ($self->y)); | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 12 | multiply ($matrix, $point); | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | =pod | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | Query distance (radius) to photo in pixels: | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | $pix_radius = $i->Radius ($pto); | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | =cut | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | sub Radius | ||||||||||||||||||||||||||||
| 401 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Radius: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 402 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 403 | 0 | my $pto = shift; | |||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 0 | my $rad_fov = deg2rad ($self->v ($pto)); | |||||||||||||||||||||||||||
| 406 | 0 | ▶ | return 0 unless $rad_fov; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 0 | my $pix_radius; | |||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ($self->{f} == 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | { | ||||||||||||||||||||||||||||
| 411 | 0 | $pix_radius = ($self->{w}/2) / tan ($rad_fov/2); | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | else | ||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||
| 415 | 0 | $pix_radius = $self->{w} / $rad_fov; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | 0 | return $pix_radius; | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 10 | 1; | |||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||