#! /bin/sh
# script to stitch flat scanned images, fov unknown
# use of fov >= 10 should be OK
# Terry Duell Jan 2014

# Using hugin tool 'pto_var' to set optimiser variables.
# Note same result can be obtained using perl-Panotools-Script tool 'ptovariable'.

# usage... ./run-scan.sh outputprefix fov

#get the output file prefix
Prefix=$1

# get the fov
FOV=$2
pto_gen --projection=0 --fov=$FOV -o project.pto scan-1.jpg scan-2.jpg
pto_lensstack -o project1a.pto --new-lens i1 project.pto
cpfind -o project1.pto --multirow project1a.pto
cpclean -o project2.pto project1.pto
linefind -o project3.pto project2.pto
pto_var -o setoptim.pto --opt TrX,TrY,TrZ,r,Eev,Ra,Rb,Rc,Rd,Re,!TrX0,!TrY0,!TrZ0,!r0,!Eev0,!Ra1,!Rb1,!Rc1,!Rd1,!Re1 project3.pto
#ptovariable --translations --response --exposure --roll -o setoptim.pto project3.pto
autooptimiser -n -o autoptim.pto setoptim.pto
pano_modify  --projection=0 --fov=AUTO --center --canvas=AUTO --crop=AUTO --blender=ENBLEND -o autoptim2.pto autoptim.pto

# comment next two lines to use hugin_executor instead of the hugin makefile stitching engine
#pto2mk -o project.mk -p $Prefix autoptim2.pto
#make -j 2 -f project.mk all

hugin_executor -s -p $Prefix autoptim2.pto
# open pto files from each step in hugin to see the steps and check how it all works
