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:
- In the Autostitch window, select menu File -> Open.
- When the open dialog appears, enter a set of image names into the edit control, and then press the "Open" button
- Wait for Autostitch to finish processing
- 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
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
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.
Options: -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.