A batch controller for Autostitch

Autostitch is an automatic 2D image stitcher. Give it a collection of partly overlapping images, and it will position and blend them into a seamless panorama. A demo version of Autostitch is available for free download. It has a simple GUI which can be used to select input images, and adjust parameters such as output resolution, cropping, and image rotation. However, the GUI interface is a little inconvenient when you have a large number of repetitive stitching tasks to perform, for example : panoramic video.

A panoramic video can be made by stitching each frame of an input video against a background panorama, as described in this earlier post. To do this we need to run thousands of separate stitching operations, each with different sets of images. Its too much to do by hand via the GUI, which is why I wrote this little batch controller for Autostitch.

The batch controller is a simple program that pretends to be a user, sending sequences of events to the GUI to simulate the normal operation of the program:

  1. In the Autostitch window, select menu File -> Open.
  2. When the open dialog appears, enter a set of image names into the edit control, and then press the "Open" button
  3. Wait for Autostitch to finish processing
  4. When Autostitch opens the preview window, close it. This makes Autostitch ready to perform the next stitching operation

Fortunately, this is not too hard to do using the Win32 API. FindWindow(NULL, name) gets us a top-level window with a given name (eg. "autostitch" or "Open"). The controls for a window can be recursively enumerated using EnumChildWindows(window, callback, data). We can use our own callback function to search based on the name or class of a control. Windows uses messages to communicate events to controls. We can generate the same messages using SendMessage. For example, to click a button:

  SendMessage(button, BM_CLICK, 0, 0);

or to enter text into an Edit control:

  SendMessage(edit, WM_SETTEXT, 0, (LPARAM) text);

If you want more details, check out the source from the download links below.


To use the batch controller, you need to first start Autostitch in the usual way. Autostitch must be "pointing" at the directory containing your source images. You can set this using the "File->Open" menu. Just select one or more images and press "Open" - it doesn't matter whether the result is successful or not. From the command-line, you can then stitch any set of images from that directory like this:

  stitch file1.jpg file2.jpg file3.jpg

This will stitch the images as usual, opening the result "pano.jpg" in the default image previewer. To run multiple stitches in sequence, the preview window must be closed before the next stitch can start. Request this by specifying -wait -close. For example:

  stitch -wait -close file1.jpg file2.jpg file3.jpg

To stitch a sequence of images, use the -template option, like this:

  stitch -template frame%03d.jpg 20 50 file1.jpg file2.jpg file3.jpg

This specifies a file name template (using sprintf syntax), and a range of file numbers. The example generates a sequence of names "frame020.jpg", "frame021.jpg", ..., "frame050.jpg". Each stitch operation combines one of the sequence names with the remaining arguments, and renames the output panorama (by default, to "out0020.jpg" ... "out0050.jpg"). Template mode automatically implies -wait -close.

Here are some simple examples using the Autostitch demo images:

  stitch -wait -close 100-0023_img.jpg 100-0024_img.jpg 100-0025_img.jpg

This stitches the bottom 3 images of the "mountain" panorama.

  stitch -path s:/stewart/programs/autostitch/images/test/ 
             -template 100-%04d_img.jpg 38 40 
             100-0023_img.jpg 100-0024_img.jpg 100-0025_img.jpg

This stitches each of the top three images (38..40) against the bottom three images, producing three outputs, "out0038.jpg" .. "out0040.jpg". (change the path to reflect your Autostitch installation).

There are a bunch of settings that you might need to change. For example, the system looks for the preview window using one of the standard applications ("pano.jpg - Windows Picture and Fax Viewer" or "Microsoft Photo Editor - [pano.jpg]"). If you have a different preview app, you'll need to change the title of the preview window using the -output option.

In "template" mode, the system renames each "pano.jpg" to a different file name using the sequence number, but to find the resulting file you need to specify the result directory using -path. Alternatively, run the stitch command from the directory containing the source images.

-help      Show help message and exit
-version   Show version and exit
-wait      Wait for Autostitch to complete (single stitch only)
-close     Close preview opened by Autostitch (single stitch only)
-template  temp start end Specify template for batch operation
           A range of images is processed for start <= id <= end. Use sprintf
           formatting (eg. id=23, temp='file%04d.jpg' -> 'file0023.jpg')
-dryrun    Just output batch image lists without calling Autostitch
-path      Path to image directory (for batch stitch). INCLUDE TRAILING '/'

Stuff you probably don't need to change:
-window    Name of Autostitch window (default: autostitch)
-status    Name of Autostitch status window (default: Status)
-output    Name of preview window (default: 'pano.jpg - Windows Picture and Fax Viewer')
-fileOpen  Menu name for File->Open dialog (default: 'File:Open')
-openTime  Delay (in ms) for open dialog to populate controls (default: 500)
-closeTime Delay (in ms) to wait before closing preview window (default: 2000)
-outjpg    Template (dir,id) for output files (default: '%sout%04d.jpg')
-outtxt    Template (dir,id) for output files (default: '%sout%04d.txt')


This app is fairly minimalist, but it should not be hard to modify if required. I used mingw + gcc which are available for free from mingw.org.

Have fun! And if you manage to create something interesting, please post a comment.

Check here for more fun with Autostitch.


  1. Ben:

    Thanks so much!

    I already got it up and running to stitch multiples as i needed. I will be playing and producing this week. i'll post some videos soon!

  2. Stewart:

    Great! I look forward to seeing what you can do with it.

  3. Didier:

    Hello Stewart

    I'm french , nobody's perfect.
    I'm very interested by the batch controller, but I fail trying it.
    I Launch Autostitch, File, Open select files everythings OK.
    Then I send for example "stitch file1.jpg file2.jpg" and get as return:
    Files : "file1.jpg" "file2.jpg"
    Control:Cannot find window 'Open'
    Do you have any idea , I'running under Windows XP SP2 in a french version.

    Thank you very much if you have an idea.

  4. Stewart:

    Hi Didier,

    I think I see the problem. The batch controller tries to find windows and controls using their names. The default values only work for English.

    Please try the current version, which adds some new options. You will need to change the following:

    This is the name of the dialog that opens when you do "File->Open" in Autostitch. In English Windows, its "Open".

    This is the name of the button you press to confirm the "File->Open" dialog. In English Windows, its "&Open". Note that the "&" should precede that shortcut character for the button, which is underlined.

    This is the name of the preview window that opens when Autostitch has finished stitching the image. In English Windows, its "pano.jpg - Windows Picture and Fax Viewer".

    For example, I guess you might need to start with:

    stitch.exe -dialogName "Ouvrir" -openName "&Ouvrir" ...

    I hope this helps. Let me know how it works.


  5. Benjamin Lotan:

    Hi there, remember me? i'm the one you posted this code for originally! finally posted something i did with it online....


    I had to do some minor tweaking to your code, but it worked great for what i wanted to do. I would have done more, cooler and higher quality stuff, and i still plan to, but other things got in the way... i'll definitely let you know next time i produce something. thanks again!

  6. Stewart:

    Hi Ben,

    That looks great! Thanks for posting it. Technically, this situation should be easier to solve, since both cameras are stationary. Once the camera transforms are calculated they should be the same for the whole movie. You can see a little bit of variation in alignment over time. I found that you can remove some of the this "jitter" by increasing the overlap between the camera views. Or you could leave it in for artistic effect. It reminds me a bit of the look of an old fashioned film reel.


  7. Elia Vecellio:

    I really appreciate a program to be able to batch process panoramas in Autostitch. However, my use is not to make video panoramas, but simply to queue up multiple panorama jobs so that the computer can process them one-by-one unattended. I am using a batch file to do this (with your stitch.exe in the source image folder). It seems that the -closeTime command-argument is not active within your program, it gets rejected as unknown (even though the documentation says it exists). I noticed it is missing from the source code. The default closeTime is only 2000ms, way too short for Autostitch to generate the preview window, on my machine its 1-2mins (ie 60000-120000ms). Im trying to hardcode the value in and re-compile, but not sure if I will succeed. Maybe you can fix it up for me? Another solution may be to get stitch.exe to simply check, say each 1000ms, if the preview window exists, and only then try to close it. Thanks. Elia

  8. Stewart:

    OK, I've fixed it. closeTime is now implemented, but instead of waiting the entire time, it polls every 2 seconds up to the time (in ms) you specify.

    For example, if you want it to wait up to 2 minutes, do:
    stitch.exe ... -wait -close -closeTime 120000

    To compile the source, you need gcc for windows, which you can get forfree from here: http://www.mingw.org

    I think it comes with a simple Windows installer. Otherwise, there are quite a few choices for what to install. I just use the basic mingw gcc compiler plus MSYS, a unix-like shell console. Once you've got it installed, just open up the MSYS shell, and do:
    gcc stitch.c -o stitch.exe
    in the source directory. Its pretty basic code, so should not be hard to modify.

    I hope this works for you. Let me know how it goes.

  9. Eric GOMARIN:

    Hi Stewart and all interested in your great job.
    I'm french too, as a compatriot already said "nobody's perfect", but that isn't the matter ;-)
    Thanks for this work and publication.
    I found one way to define autostitch's working directory : you only have to launch it form a directory which contains a file named toto.jpg whatever it contains.
    You can then queue panorama jobs on several other directories specifying your source image files with absolute pathnames. The result will be in autostitch working directory. You just need to rename or move the generated pano to the place you wish.
    Hoping this will help.

  10. ana:

    Hi Stewart

    I want run the autostitch using mingw + gcc but i can't understand the step...
    can you help me..
    plz... i need ur help...

  11. Stewart:


    Thanks Eric, that's useful to know. Its certainly handy to be able to define Autostitch's working directory.

    Glad to hear you're able to get some use out of the program.

  12. Thierry:

    Hello I am new to autostich. I am evaluating it.

    ==> Very imprisessive the batch process.
    I am still hesitating to use it because well .... it's a hack as you said.
    But defenatly your batch thing is realling someting that has a wonderfull value for autostich.

    Thanks stewart for posting the .exe

  13. Mihai Diac:

    Hi. I used your solution and extended it with a script to match my needs. Check it out:


    It works, but still, I don't like it too much. If autostitch would have the proper command-line arguments, everithing would be much cleaner. Have you tried contacting them ?


  14. Stewart:

    Hi Mihai,

    Glad you found the batch processor useful. I like the idea of grouping photos in folders - that would be useful if you take lots of panoramas.

    I think the Autostitch algorithms are licensed to various vendors of photo management apps, so I think its probably not in their interests to make the demo version too useful. If the free version could be easily embedded/controlled they would probably not make many sales.

  15. Tanner:


    I run a German version of Windows. My "Open" Button is named "Öffnen". That might be the reasion why it does not work:

    Control : Cannot find dialog "Open"

    Could you please send me a version works for German? I do not have a C compiler and I do not know C programming...

    By the way: "Close" is "Schliessen"


  16. Stewart:

    Hi Tanner,

    There are two places where the batch controller looks for the names of dialogs and controls which in English are labeled "Open". You can specify alternative names via the command-line. For example:

    stitch.exe -dialogName "Öffnen" -openName "Öffnen" …

    For more info, check this comment which describes how to make it work in French:


    Hope this helps.


  17. Robbie Longcat:

    hey there stewart, i've been using autostitch for a while now and i've just stumbled on your batch processing thing... it will take me a little minute or 2 to get it running but it's just what i need right now... thanks, i'll feedback as i go along x

Leave a comment