After having difficulty displaying partial panoramas, I decided to put 
together a script to correctly calculate min/max Pan and Tilt from value 
pulled from the PTO file.  Here's what I've got so far.  Hopefully it will 
be useful to others.

In the fast preview, there is a projection tab that shows the entire 
projection canvas.  The FOV numbers on that tab refer to the canvas, not 
the cropped image.  With a couple of calculations, it is possible to come 
up with the correct numbers for the cropped image instead.  Note that you 
must have the horizon placed properly in the panorama for the numbers to 
work out right for viewing.  The script pulls the relevant information from 
the PTO file and performs the pixel offset calculations to determine the 
correct FOV for the cropped final image.  

Requirements: Bash, bc, vaild PTO
usage: autoPanTilt <PTO file>

I don't claim to be a wizard Bash scripter, but from my initial testing, 
the script seems to work both for equirectangular and cylindrical 
panoramas.  It is pretty trivial to take the values in the code and 
generate PUREPlayer html and xml files for viewing as well as using 
ImagMagick convert to resize and convert your images for web viewing.  I 
haven't gotten that far yet, and even if I did, I think that the EULA may 
prevent my releasing that section of the code.  In any case, it's basically 
just plugging in at that point.  

Enjoy,
Bill

-- 
-- 
You received this message because you are subscribed to the Google Groups 
"Hugin and other free panoramic software" group.
A list of frequently asked questions is available at: 
http://wiki.panotools.org/Hugin_FAQ
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/hugin-ptx

--- 
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].
For more options, visit https://groups.google.com/groups/opt_out.


#!/bin/bash
# This script pulls FOV information from a pto file to apply to an image.
# Note: the image must have been generated from the pto file.  Changes to a
# pto file or resulting image's dimensions will result in inaccurate values.


# --- Pull Data from the PTO ---
# this is our test image.
#file="test.pto"
file=$1
# first grep the "p" line.  Then split the data.  Then grep only what 
# we're interested in working with.
info=$(egrep -e '^p' $file | tr " " "\n" | egrep -e '^[fwhvS]')

# --- Parse Data from PTO ---
for item in $info
do
  # the first character is the info type
  mytype=${item:0:1}
  # remaining characters are the value (not always 1 number)
  myval=${item:1}
  # pull each piece of information correctly
  case $mytype in
    f)
      # we handle two projections for now: cylindrical(1), and 
equirectangular(2)
      #echo "Projection type is $myval"
      case $myval in
      1)
      projection="Cylindrical"
      ;; 
      2)
      projection="Equirectangular"
      ;;
      esac
    ;;
    w)
      #echo "Image width is $myval"
      width=$myval
    ;;
    h)
      #echo "Image height is $myval"
      height=$myval
    ;;
    v)
      #echo "Image horizontal FOV is $myval"
      fullFOV=$myval
    ;;
    S)
      # crop data must be parsed again.
      #echo "Image Crop string is $myval"
      OFS=$IFS
      IFS=',' read -a cropParse <<< "$myval"
      left=${cropParse[0]}
      right=${cropParse[1]}
      top=${cropParse[2]}
      bottom=${cropParse[3]}
      IFS=$OFS
    ;;
  esac
done

# --- Calculate Values of Interest ---
# width and height are pre-cropped values.  
# Therefore fullFOV/width = degFOV/pixel.  Use this to calculate minpan/maxpan 
from center
minPan=$(echo "scale=3; ($left -   (($right - $left ) / 2 + $left ))*$fullFOV / 
$width" | bc -q 2>/dev/null)
maxPan=$(echo "scale=3; ($right -  (($right - $left ) / 2 + $left ))*$fullFOV / 
$width" | bc -q 2>/dev/null)

# if the panorama is created correctly, then the horizon of the image
# is exactly in the middle (height/2). 
minTilt=$(echo "scale=1; (($height - $bottom ) - ($height / 2))*$fullFOV / 
$width" | bc -q 2>/dev/null)
maxTilt=$(echo "scale=1; (($height - $top    ) - ($height / 2))*$fullFOV / 
$width" | bc -q 2>/dev/null)

# report on info
echo "Processed Panorama: $file"
echo "Projection: $projection"
echo "Projection Size: $width x $height"
echo "Horizontal FOV: $fullFOV"
echo "Cropping: l-$left, r-$right, t-$top, b-$bottom"
echo
echo "Pan  = {${minPan}:${maxPan}}"
echo "Tilt = {${minTilt}:${maxTilt}}"

echo
echo

Reply via email to