Ignore that last question .. I see that won't work.
Here, as promised, is the script I put together. Plenty of room for improvement...
/* --------------------------------------------------------------- */
/* huginpan.rex --- run Hugin with layout hints */
/* --------------------------------------------------------------- */
/* */
/* Call as: */
/* */
/* huginpan pattern lens columns rows order */
/* */
/* where: */
/* */
/* pattern -- source files pattern (e.g., P*.jpg) */
/* lens -- lens length (mm, 35mm equivalent) */
/* columns -- number of images in X dimension */
/* rows -- ditto in Y */
/* order -- mapping of image sequence to rectangle */
/* */
/* pattern, lens, and columns are required */
/* rows default=1, order default=0 */
/* */
/* order is: */
/* */
/* 0 -- rows, left->right, top->bottom (start top-left) */
/* 1 -- columns, top->bottom, left->right (start top-left) */
/* */
/* Before using this, it is suggested that you copy the source */
/* files to their own subdirectory, then run this command with */
/* that as the current directory. */
/* */
/* Return codes from pto_ commands are not documented, so ignored. */
/* --------------------------------------------------------------- */
-- 2015.11.04 mfc initial vesrion
-- 2015.11.06 add lens length as parameter
-- ensure path to Hugin 64-bit programs [needed for cpfind]
'SET PATH=c:\Program Files\Hugin\bin;%PATH%'
parse arg pattern lens columns rows order .
if columns='' then do
say 'Pattern, lens, and columns must be specified'
exit -1
end
if rows='' then rows=1
if order='' then order=0
-- set up constants (could be parameters or options, later)
-- short-edge equivanet sensor size is assumed to be as 4:3 35mm (27mm)
aspect=4/3 -- sensor horizontal:vertical ratio
portrait=0 -- 1 if camera in portrait (vertical) format
overlap=0.4 -- overlap between images as a fraction
-- calculate total degrees vertical and horizontal
h=2*arctan((27*aspect) / (2*lens)) -- sensor horizontal degrees
v=2*arctan(27 / (2*lens)) -- ditto vertical
if portrait then do -- swap if portrait
temp=h
h=v
v=temp
end
-- now have degrees for h and v for one image
say 'Image degrees:' h 'x' v
totalh=h*(columns - overlap*(columns-1))
totalv=v*(rows - overlap*(rows-1))
say 'Total degrees:' totalh 'x' totalv
-- set up the pitch and yaw formulae
-- absolute origin non-critical
eh=h*(1-overlap) -- effective horizontal degrees
ev=v*(1-overlap) -- effective vertical degrees
offseth=totalh/2 - h/2 -- offset for 0,0 image
offsetv=totalv/2 - v/2 -- ..
select
when order=0 then do -- TL, by row, left->right
yaw='(i%'columns')*'eh'-'offseth
pitch=offsetv'-(floor(i/'columns')*'ev')'
end
when order=1 then do -- TL, by column, top->bottom
yaw='(floor(i/'rows')*'eh')-'offseth
pitch=offsetv'-(i%'rows')*'ev
end
otherwise do
say 'Bad order specified:' order
exit -1
end
end
say 'yaw='yaw 'pitch='pitch
----- process the images using Hugin commands -----
profile='project.pto' -- project filename
call sysfiledelete profile
-- create the Hugin project file
'pto_gen -o' profile pattern
-- update/set rough geometricals
'pto_var "--set=y='yaw',p='pitch'" --output='profile profile
-- find control points
'cpfind --output='profile '--prealigned' profile
-- add missing control points using geometry
'geocpset --output='profile profile
-- done
say
say 'Starting Hugin. Open' profile', Align, and Generate Panorama'
'start "Hugin" Hugin'