A few of my favorite things:
My sample script stitches together images that have overlapping areas. It takes in an input directory and output directory in the command line.
#!/usr/bin/env python3
#
# stitch.py
#
# VERSION 1
#
# LAST EDIT: 09/14/2021
#
# Author: Laura Brancati, based on function found on: https://www.pyimagesearch.com/2018/12/17/image-stitching-with-opencv-and-python/
#
# Stitches images together that have overlapping areas.
#
##############################################################################
# REQUIRED MODULES
##############################################################################
import os
import argparse
import cv2
import imutils
import numpy as np
##############################################################################
# FUNCTIONS
##############################################################################
def image_stitch(img_directory, output_path):
= img_directory
img_dir = os.listdir(img_dir)
names
#get all of the image file names from the directory and put them in a list
= []
images for name in names:
= os.path.join(img_dir, name)
img_path = cv2.imread(img_path)
image
images.append(image)
#call stitch function and stitch images; status is 0 if succesfull
= cv2.createStitcher() if imutils.is_cv3() else cv2.Stitcher_create()
stitcher .8)
stitcher.setPanoConfidenceThresh(= stitcher.stitch(images)
status, stitched
if status==0:
# create stitched image file
+".jpg"), stitched)
cv2.imwrite(os.path.join(output_pathprint("success!")
else:
print("status:", status)
##############################################################################
# MAIN
##############################################################################
if __name__ == "__main__":
= argparse.ArgumentParser(
p ="stitch images together that are in a directory")
description"-i", "--images", type=str, required=True,
p.add_argument(help="path of input directory of images to stitch")
"-o", "--output", type=str, required=True,
p.add_argument(help="path to the output image")
= p.parse_args()
args
#call function
= image_stitch(args.images, args.output) stitched