Command line interface for hugin please

1,131 views
Skip to first unread message

Jan Martin

unread,
Nov 20, 2010, 3:17:49 PM11/20/10
to hugi...@googlegroups.com
Hi all,

you might already know that I am working on a streetview rig at http://www.diy-streetview.org

One component missing is a way to stitch the images automatically into panoramas.
My basic nona and enblend based Perl script solution appears more and more to be a waste of time.
It barely duplicates what hugin already does better.

Therefore I'd like to propose a command line interface for hugin.

Structure:
hugin
file.pto (does not change for a streetview rig)
"all the options and buttons from the hugin Stitcher tab"
-v = verbose output
-nogui = do not display a gui at all, terminal window only
-o output folder

I am sure there is more to think of.
The panotools and nona and enblend command line options are a  good inspiration.

Any chance for this?

Thanks,
Jan

--
http://www.DIY-streetview.org

dmg

unread,
Nov 20, 2010, 4:30:18 PM11/20/10
to hugi...@googlegroups.com
What part of hugin do you want to automatize?

Bruno has been creating scripts to create automatic panoramas for some time.

--dmg

> --
> 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 hugi...@googlegroups.com
> To unsubscribe from this group, send email to
> hugin-ptx+...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/hugin-ptx
>

--
--dmg

---
Daniel M. German
http://turingmachine.org

Jan Martin

unread,
Nov 20, 2010, 4:54:07 PM11/20/10
to hugi...@googlegroups.com
Hi Daniel,

I have a .pto file and need to stitch it.
Output needs to be an equirectangular .jpg file at 95% quality.

Right now I use a Perl script that runs fulla, vig_optimize, nona and enblend.

But the result is not as good as what hugin does with the same .pto, and me just clicking the "Stitch now!" button on the Stitcher tab.

So that is what I am looking for.

Jan
http://www.DIY-streetview.org

dmg

unread,
Nov 20, 2010, 4:57:42 PM11/20/10
to hugi...@googlegroups.com
Yes, that is what his scripts do: panotools script.

--dmg

On Sat, Nov 20, 2010 at 1:54 PM, Jan Martin

john doe

unread,
Nov 20, 2010, 5:27:59 PM11/20/10
to hugi...@googlegroups.com
could i see the perl script??id like to stitch lots of jpgs taken from varios video sources..

so far i have gotten to the point to almost automatize the stitching progress with a perl script, but i would like to automatically batch stitch and spawn one .pto to all files in a given folder, is this possible??

James Legg

unread,
Nov 20, 2010, 8:16:11 PM11/20/10
to hugi...@googlegroups.com
On Sat, 2010-11-20 at 14:54 -0700, Jan Martin wrote:
> I have a .pto file and need to stitch it.

You can generate a makefile from a pto with pto2mk, then run make on
that to generate the same output as Hugin's "Stitch Now!" button. For
example:

pto2mk -o project.pto.mk -p project project.pto
make -f project.pto.mk

This page of the panotools wiki is useful for scripting things Hugin
does: http://wiki.panotools.org/Panorama_scripting_in_a_nutshell


-James

john doe

unread,
Nov 20, 2010, 8:26:44 PM11/20/10
to hugi...@googlegroups.com
how about i wanted to make several pto files to stitch a bunch of files in a folder??is there a thing as mass spawning a pto file to apply it to other picture files in a folder??that would literally save me hours of work..lets say in one .pto file i have picture files img0001A.jpg and img0001B.jpg, lets imagine they are taken from 2 stereographic cameras, this is a hypotethical case, im working with about 10 video sources..

THe next row of files are img0002A.jpg-img0002B.jpg, and so on, since they are part of a 1 minute video, forming at least 200 files..

How would i apply the .pto file to the rest of the jpgs in the folder??hypotethically assuming they all have the same width, height, cropping ..




--

kfj

unread,
Nov 21, 2010, 1:18:51 PM11/21/10
to hugin and other free panoramic software


On 21 Nov., 02:26, john doe <guerrerodelu...@gmail.com> wrote:

> How would i apply the .pto file to the rest of the jpgs in the
> folder??hypotethically assuming they all have the same width, height,
> cropping ..

The easiest way is to use placehoder names lime image1.tif image2.tif
in the pto and successively rename your images to the placeholder
names, stich, and rename back.
If you want separate ptos, the pto is a simple text file. So you can
work on it with batch text processing tools. One tool to efficiently
perform tasks like the one you need is awk, or, in it's GNU
incarnation, gawk. It should be already there on every UNIX and Linux
system; for Windows you'll get it as part of cygwin or minGW or even
standalone, Mac OS I don't know, but since it runs on top of UNIX, it
probably has it as well. If your pto, let's say it's called xx.pto, is
of the dialect keeping the file name in i lines you'd use template
names like 'image1.tif' and 'image2.tif' in the pto and then use an
awk script like:

/^i/ { gsub ( /image1/ , i1 , $0 )
gsub ( /image2/ , i2 , $0 )
}

{ print
}

you save that as chgimg.awk
If you call it like

gawk -f chg_img.awk i1=image7 i2=image8 xx.pto > xx1.pto

gawk would change image1 to image7 and image2 to image 8.

If your pto is of the dialect using #-imgfile lines to give the image
name, change the pattern in the first line of the awk file to

/#-imgfile/

and it will do the same.

If you now call your awk script in a loop, you can generate a bunch of
ptos doing the desired task:

i=0
imglist=($(ls *.tif))
while [[ -a ${imglist[$i]} ]] ; do chgimg.awk i1=${imglist[$i]} i2=$
{imglist[$i+1]} xx.pto > xx$i.pto; let i=i+2; done

if you get my drift ;-) - sorry, my shell scripting is a bit rusty,
I'm sure any UNIX wizard will do the same with half the amount of
letters (this is using bash, the bourne again shell)

... all that said, let me add that I did a bit of research into the
matter, since your task is such an obvious one one should think there
is a ready-made tool for it. There probably is, and hopefully someone
will soon post something like 'pano_xyzzle_buthle' changes image name
in i-lines, if you call it with the --piccie parameter.... I looked at
likely candidates among the scripts that handle pto files, but all I
found was extremely meagre documentation. It made me really angry.
Like there is 'hugin_stich_project'. It is a command line tool to
stitch a hugin project. It states

Verwendung: hugin_stitch_project [-h] [-o <str>] [-t <num>] [-d]
[<project> <images>...]
-h, --help show this help message
-o, --output=<str> output prefix
-t, --threads=<num> number of threads
-d, --delete delete pto file after stitching

... and that's it. (there is a man page which says the same in
slightly more words). So one would assume that one could maybe call it
with a bunch of images and a pto. How's the pto to be? without i-
lines? no joy. With i-lines? If you omit the names in the i-lines, it
just won't work. Leave the names in the i-lines and it will ignore the
<images> you passed. I looked at the source code of it (even...) -
hardly a comment to be seen, totally illegible. So here was a person
competent enough to write a piece of reasonably complex software in C+
+ consisting of 14400 characters of code (I counted). And the
documentation is what you see above. What do the <images> in the
command line do?

Then there's a script called ptsed. It can change an image name in a
pto file. Bit cryptic, call it like

ptsed -o xx1.pto -I n/0:xxxx xx.pto

And it will change the name of the first image in xx.pto to 'xxxx' and
write the modified script to xx1.pto. The documentation was so thin I
had to guess my way. I didn't manage to figure out how to specify that
I want several file names changed at once.

And so on. I lost patience.

Personally, I use Python and so far I've set up a few scripts to help
me wrangle with the jungle of pto dialects. But I'm not quite there
yet to upload my scripts. If I do, I promise that the documentation
will be better...
until then, hope for a more helpful post then mine

with clenched jaw from grinding my teeth
Kay

Jan Martin

unread,
Nov 21, 2010, 1:33:45 PM11/21/10
to hugi...@googlegroups.com
Hi Kay,

I totally understand your frustration from experience.
It seems there is a simple way to do what you want:

http://wiki.panotools.org/Panorama_scripting_in_a_nutshell#Simple_command-line_stitching

Excerpt:
....This example takes a pre-existing project called template.pto, created with three photos. It uses nona for remapping, and enblend for blending the remapped photos into a finished TIFF image:
 nona -o out -m TIFF_m template.pto DSC_1234.JPG DSC_1235.JPG DSC_1236.JPG
enblend -o finished.tif out0000.tif out0001.tif out0002.tif

The first nona command creates three remapped TIFF images called out0000.tif, out0001.tif etc... the list of input images can be substituted with any set of identically sized photos. The second enblend command uses these TIFF files as input and merges them to a file called finished.tif.....

Jan




--
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 hugi...@googlegroups.com
To unsubscribe from this group, send email to hugin-ptx+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/hugin-ptx



--
http://www.DIY-streetview.org

Bruno Postle

unread,
Nov 21, 2010, 4:04:30 PM11/21/10
to Hugin ptx
On Sat 20-Nov-2010 at 14:54 -0700, Jan Martin wrote:
>
> But the result is not as good as what hugin does with the same
> .pto, and me just clicking the "Stitch now!" button on the
> Stitcher tab.

You should be able to reproduce exactly the results of using the
1,2,3 buttons from the Hugin Assistant with icpfind, autooptimiser
and pto2mk (icpfind is only in the current HG tip).

--
Bruno

john doe

unread,
Nov 21, 2010, 4:41:15 PM11/21/10
to hugi...@googlegroups.com
KFJ!!dude youre the man!!!thanks for informing me about gawk!!i didnt know it could do that...i was reading a bit about panotools script, but almost all the tools work on a single pto file..and all th escripts i ahve seen so far are based on a single pto file..whatever name it has, like template.pto..

Iḿ really interested in both gawk and that ptsed tool you mentioned...didnt know about it..

thanks a bunch for the info..and your scripts are nice..


--

kfj

unread,
Nov 22, 2010, 3:13:38 AM11/22/10
to hugin and other free panoramic software


On 21 Nov., 22:41, john doe <guerrerodelu...@gmail.com> wrote:
> Iḿ really interested in both gawk and that ptsed tool you mentioned...didnt
> know about it..

What platform are you on?

I have used awk/gawk a lot when I was still working as a programmer,
so I can probably help if your efforts become more involved. awk is
much more powerful than just changing a few words in a bit of text.
Everyone who's into scripting would do well to learn at least a bit of
it; many tasks that seem daunting otherwise become very easy indeed.

Awk is really good at text processing, but that is also it's main
scope. As a general purpose language it becomes a bit awkward. If you
want a tool that can do everything awk does plus everything else you'd
expect from a programming language, go for Python. You won't regret
it. In Python you can also use regular expressions to pick out bits of
text and then change them to something else; since it's general-
purpose, it's more verbose but also much more flexible.

ptsed is part of the Panotools-Script package:

http://search.cpan.org/dist/Panotools-Script/

This is a collection of perl scripts to deal with pto files. It has a
lot of good stuff in there, but the documentation is at times a bit
scanty. For me, the problem is that the scripts are in perl (don't
worry, you can just use them without knowing what language they're in)
- and I can't - at least now - get myself to learn perl. They work
just fine, though.

> thanks a bunch for the info..and your scripts are nice..

No big deal - I just tried to point you in the right direction, you
can hardly call these snippets 'scripts'... As Jan Martin has pointed
out above, there is a helpful introduction to panorama scripting in
the panotools wiki:

http://www.google.com/url?sa=D&q=http://wiki.panotools.org/Panorama_scripting_in_a_nutshell%23Simple_command-line_stitching&usg=AFQjCNFyQ7ku1BjMRkrsj8HgfUdRqei8og

with regards
Kay

Eric O'Brien

unread,
Nov 22, 2010, 4:00:54 AM11/22/10
to hugi...@googlegroups.com
Didn't I just say something about some documentation being a bit ...
sparse?

Please, all you programmers out there:

Take an additional hour or so, after you are "done" with the Real
Work, and expand the "help" and man files.

Then take yet another hour, go back over your code and add some
comments. (Well, really, you should be commenting as you go.
Shouldn't you?)

Coolness isn't cool if nobody but yourself and three buddies can use
it / make sense of it.

Come on now, everybody reach for the next level TOGETHER. ;)

Thanks,

eo


On Nov 21, 2010, at 10:18 AM, kfj wrote (in part):

> .... I looked at likely candidates among the scripts that handle pto
> files, but all I
> found was extremely meagre documentation. It made me really angry.
> Like there is 'hugin_stich_project'. It is a command line tool to
> stitch a hugin project. It states
>
> Verwendung: hugin_stitch_project [-h] [-o <str>] [-t <num>] [-d]
> [<project> <images>...]
> -h, --help show this help message
> -o, --output=<str> output prefix
> -t, --threads=<num> number of threads
> -d, --delete delete pto file after stitching
>
> ... and that's it. (there is a man page which says the same in
> slightly more words).
>

> . . .
>
> I lost patience.


>
>
> with clenched jaw from grinding my teeth
>
> Kay
>

> --

paul womack

unread,
Nov 22, 2010, 4:53:08 AM11/22/10
to hugi...@googlegroups.com
kfj wrote:
>
> I have used awk/gawk a lot when I was still working as a programmer,
> so I can probably help if your efforts become more involved. awk is
> much more powerful than just changing a few words in a bit of text.
> Everyone who's into scripting would do well to learn at least a bit of
> it; many tasks that seem daunting otherwise become very easy indeed.
>
> Awk is really good at text processing, but that is also it's main
> scope. As a general purpose language it becomes a bit awkward. If you
> want a tool that can do everything awk does plus everything else you'd
> expect from a programming language, go for Python. You won't regret
> it. In Python you can also use regular expressions to pick out bits of
> text and then change them to something else; since it's general-
> purpose, it's more verbose but also much more flexible.

"back in the day" (g)awk was useful (and I used it).

However, with perl now so mature and widely installed
(or installable) I view awk as of historical interest
only.

I use, and would recommend, perl as a "scripting glue" language.

Perl has a helpful combination of syntactic convenience
and a huge library of pre-cooked code.

BugBear

kfj

unread,
Nov 22, 2010, 8:17:35 AM11/22/10
to hugin and other free panoramic software


On 22 Nov., 10:53, paul womack <pwom...@papermule.co.uk> wrote:
> "back in the day" (g)awk was useful (and I used it).

it is still on every UNIX-like system, ready to go. Ubiquitous.
Allowed me to just write a five-liner to be run from the shell
to make my point.

> However, with perl now so mature and widely installed
> (or installable) I view awk as of historical interest only
> I use, and would recommend, perl as a "scripting glue" language.

I use, and would, and did recommend Python as a scripting language.
I suspect perl is as powerful. Python got me first. And as far as
(most?) Linux systems go, Python is already there - no need to
install anything.

> Perl has a helpful combination of syntactic convenience
> and a huge library of pre-cooked code.

I had a good look at Panotools-Script. I can only subscribe to what
Eric O'Brien
wrote above. It may be extremely cool code, but I found it very hard
to
figure out what it actually did. I feel that Python is more legible.

with regards
Kay

john doe

unread,
Nov 23, 2010, 12:12:20 PM11/23/10
to hugi...@googlegroups.com
thanks for the replu KFJ im working un ubuntu linux..

kfj

unread,
Nov 23, 2010, 1:42:19 PM11/23/10
to hugin and other free panoramic software


On 23 Nov., 18:12, john doe <guerrerodelu...@gmail.com> wrote:
> thanks for the replu KFJ im working un ubuntu linux..

Ah. Great. Me too. So you have awk, Python, perl if you want it, the
works.
Scripting really is where you take control of computing. GUIs are
nice, but they tend to reach their limits when you want to do more
complex and involved stuff. After all, you can't talk to a GUI...

with regards
Kay

john doe

unread,
Nov 23, 2010, 2:22:30 PM11/23/10
to hugi...@googlegroups.com
hey i dont talk to GUIs i talk to GALs...sorry for the bad joke LOL...

anyways, im reading a bit into scripting...i understand mostly perl based scripting...what do you recommend for beginners?please keep in mind that im not a programmer...

i need a scripting language that suits the needs ive told you KFJ..

im trying with qt4 right now.


with regards
Kay

kfj

unread,
Nov 24, 2010, 10:20:41 AM11/24/10
to hugin and other free panoramic software


On 23 Nov., 20:22, john doe <guerrerodelu...@gmail.com> wrote:
> anyways, im reading a bit into scripting...i understand mostly perl based
> scripting...what do you recommend for beginners?please keep in mind that im
> not a programmer...
>
> i need a scripting language that suits the needs ive told you KFJ..
>
> im trying with qt4 right now.

I find it very hard to give you advice on that, because I'm an ex-pro
and have been using and programming computers quite intensely for some
30 years now. So I can't really judge what is good for a beginner. If
you are serious and want to learn a powerful language that has a scope
from scripting to general purpose application programming, I'd
recommend Python, but I'm biased, because I'm a Python user myself,
and I already know a fair number of programming and scripting
languages - I've even done a fair bit of language design. So what I
think is an ideal tool may be too powerful and too complex for you. It
is very accessible and well-documanted, though, just visit python.org,
you'll see.

When it comes to panorama scripting, a lot of code has been written
already in perl. You can either use the ready-made scripts, or try and
adapt them to your needs by modifying them or taking bits from them
and building your own on top. You may have noticed, though, that the
existing scripts often aren't very well documented, so this process
may be less efficient than you'd wish for. I don't know perl, so I
can't help you there, but if you ask specific questions here, the
authors or experienced users of the code should notice and give you
competent answers.

When I look at your problem of just changing a few i-lines in a
template panorama to stitch the same thing with different images, I
feel that even a scripting language is more than you might need. It
looks to me as if you could pretty much get the task done with a shell
script and the odd call to one of the preexisting perl scripts or
other command line tools. You might even get away with very little
scripting if you adopt clever storage schemes for your data, i.e.
putting the images for each panorama into a separate folder, naming
them img00.tif - img09.tif, and copying the template script into the
folder. The script should pick the images from the folder it's in if
it has just the file names in th i-lines, not the full path. Setting
it up this way, all you need is a shell script setting up the folders
and copying and renaming the files. Learning to write shell scripts is
well worth the effort anyway, because they are widely used, and if
you're competent with the shell, you can work very efficiently from
the command line, and the shell already has methods to deal with
files, variables, arrays, pattern matching, and so on - only the
syntax is a bit cryptic.

with regards
Kay

john doe

unread,
Nov 24, 2010, 12:56:16 PM11/24/10
to hugi...@googlegroups.com
thanks for the advice KFJ, right now im into perl..as you mentioned im learning from reading some other perl scripts that uses hugin command line tools and other software for HDR imaging..as for the file naming i used a common approach to the video sources, almost like the one you mentioned...i wish somebody in hugin development tool could overhoul the batch processing mode to allow this..


with regards
Kay

Bruno Postle

unread,
Nov 24, 2010, 1:04:01 PM11/24/10
to hugin and other free panoramic software
On Wed 24-Nov-2010 at 07:20 -0800, kfj wrote:

> When it comes to panorama scripting, a lot of code has been
> written already in perl. You can either use the ready-made
> scripts, or try and adapt them to your needs by modifying them or
> taking bits from them and building your own on top. You may have
> noticed, though, that the existing scripts often aren't very well
> documented

Documentation for Panotools::Script is here:
http://search.cpan.org/dist/Panotools-Script/

--
Bruno

kfj

unread,
Nov 24, 2010, 4:24:17 PM11/24/10
to hugin and other free panoramic software
Sorry Bruno, my post wasn't quite accurate. I should have said
'commented' not 'documented'. I meant more the aspect of trying to
adapt the scripts by modification - when I looked into some of the
scripts (and, again, I have to admit that weren't too many), I would
have wished for more comments to explain what was happening in them.

with regards
Kay
Reply all
Reply to author
Forward
0 new messages