Feb 1, 2010

Hugin and autopano-sift-c

Hugin is an awesome panorama photo stitcher. It can optionally use a helper program - autopano-sift-C - to pre-align the photos into a panorama automatically. Autopano searches for common elements (called control points) between all the images and feeds them back to Hugin to put the puzzle together. Hugin works fine without it, but in that case control points need to be created manually, which can be a laborious task.

The autopano-sift-C program is not shipped with Fedora because it is patent-encumbered in the US (the SIFT algorithm it uses is patented by the University of British Columbia). It can be found, however, as an RPM package in the RPM Fusion repository.

At this time Hugin has a problem loading more than 124 images at a time when autopano-sift-C is in use. You get the following error message:

Could not execute command: autopano-sift-c

If you look in the X session errors there's this:
$ tail -2 ~/.xsession-errors
...AutoCtrlPointCreator.cpp:1a7) automatch(): Too many arguments for call to wxExecute()
...AutoCtrlPointCreator.cpp:1a8) automatch(): Try using the %s parameter in preferences
The problem is that autopano-sift-c takes the image names separately on the command line and Hugin can't pass more than 127 parameters to it (this being a limitation of the toolkit it uses). The quick and dirty solution is to use an external script to convert a file containing image filenames to parameters:
#!/bin/bash
# Change Hugin Preferences -> Autopano as follows:
# Autopano-SIFT: path to this script
# Arguments: --maxmatches %p %o %namefile
dos2unix $4
exec autopano-sift-c --align $1 $2 $3 `cat $4`

And voila! Hugin can now load and prealign very large image sets. If you have spaces in filenames then you might need to massage that last part a bit to quote each name, but otherwise this should work just fine.

6 comments:

  1. Looks great. I'll try your Script with Ubuntu. But do you have a solution for Windows?

    ReplyDelete
  2. GR8! It works! Thanks a lot, mate!

    ReplyDelete
  3. Laurentiu,

    I've encountered an identical problem with autopano-sift-c and with help of your post I managed to solve it. However, the shell script did not work in my case, and it will not work if the path to the image contains shell special characters (such us whitespaces).
    Knowing the root of the problem and an approximate solution I wrote a small perl wrapper for autopano-sift-c, which works for any paths and file names:

    #!/usr/bin/perl -w
    use strict;

    my @a;
    push @a, ("/usr/bin/autopano-sift-c","--align",@ARGV[0..2]);

    open F,"<",$ARGV[3] or die "Can't open file $ARGV[3]\n";
    while()
    {:w

    s/[\r\n]//g;
    push @a,$_;
    };

    close F;

    exec @a;

    ReplyDelete
  4. Your bloody Marvelous, how the heck did you figure out that it was the newline character... Anyway, for Debian/Ubinti you have to:
    apt-get install tofrodos
    and change things a little bit.
    For Panomatic I have the following:

    # Arguments -o %o %namefile
    exec panomatic $1 $2 `cat $3 |fromdos`

    Anyway. much thanks. this helps someone.
    Add the keywords:
    Too many arguments (images). Try using the %s parameter in preferences.

    I came across another quirk, and that is that the pathnames get truncated at certain length too! had to move the image source closer to root dir!

    ReplyDelete
  5. The bash and pearl script for autopano-sift-c does not work for me. I don't know what I am doing wrong. I copied the script, made it executable, added the path in Hugin and the stated arguments. I get a errormessage with code 127 (bashscript) or 255 (for pearlscript).

    The script for panomatic does work, but I would like to get the script for autopano-sift-c working aswell.

    Could someone pleas help me?

    ReplyDelete
  6. I do not understand: how do you pass the file containing the image filenames as a parameter to the script within the Hugin GUI. I guess you must open a particular file type...
    I'm running Hugin with Ubuntu.

    Please Help!

    ReplyDelete

Please keep your message on topic if at all possible...