Fast and Robust Image Stitching with Python’s Stitching Package

Sep 6, 2022 | Data Science

Welcome to your guide on a fantastic Python package designed for fast and robust image stitching. Based on OpenCV’s stitching module and inspired by the stitching_detailed.py command-line tool, this package allows you to effortlessly create stunning panoramas from your images.

Installation

Installing the stitching package is a breeze. You can use either the Docker image or pip from PyPI:

pip install stitching

Usage

Once installed, you’re ready to unleash the stitcher!

Python CLI

The command-line interface can be accessed after installation. Here are some commands you can use:

  • stitch -h – Show the help menu.
  • stitch *.jpg – Stitches all JPG files in the current directory.
  • stitch img_dirIMG*.jpg – Stitches all files in the img_dir directory starting with IMG and ending with .jpg.
  • stitch img1.jpg img2.jpg img3.jpg – Stitches the three specified files.
  • stitch *.jpg -v – Enables verbose mode, allowing for easy troubleshooting.

Docker CLI

If you’re more comfortable using Docker, you can use the Docker image as follows:

docker container run --rm -v pathtodata:data openstitching/stitch:version -h

This will give you similar functionalities as the Python CLI.

Python Script

For programmatic access, use the Stitcher class in your Python scripts:

from stitching import Stitcher
stitcher = Stitcher()

To specify custom settings:

stitcher = Stitcher(detector=sift, confidence_threshold=0.2)

Create a panorama from your images using:

panorama = stitcher.stitch([img1.jpg, img2.jpg, img3.jpg])

You can also use wildcard patterns and loaded images just as easily.

Troubleshooting

While stitching images can be straightforward, issues may arise. Here are a few tips to help you troubleshoot:

  • Ensure that your images have enough overlap for the stitcher to work effectively.
  • Check if your images are in the correct format (preferably JPG).
  • If you encounter errors, use the verbose mode (-v) to inspect intermediate results and identify problematic images.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Tutorial and Literature

This package also provides utility functions for detailed analytics. A comprehensive tutorial is available in a Jupyter Notebook, where you can visualize RANSAC matches and seam lines.

This package was developed for the paper on Automatic stitching of fragmented construction plans of hydraulic structures.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox