Skip to content

Instantly share code, notes, and snippets.

@ola0x
Created March 12, 2022 14:31
Show Gist options
  • Save ola0x/2ec6d705c2c9f72615683f3a81c2d554 to your computer and use it in GitHub Desktop.
Save ola0x/2ec6d705c2c9f72615683f3a81c2d554 to your computer and use it in GitHub Desktop.
from imutils import paths
import cv2
import numpy as np
import argparse
import imutils
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", type=str, required=True,
help="path to input directory of images to stitch")
ap.add_argument("-o", "--output", type=str, required=True,
help="path to the output image")
args = vars(ap.parse_args())
# grab the paths to the input images and initialize our images list
print("[INFO] loading images...")
imagePaths = sorted(list(paths.list_images(args["images"])))
images = []
# loop over the image paths, load each one, and add them to our
# images to stitch list
for imagePath in imagePaths:
print("!")
image = cv2.imread(imagePath)
images.append(image)
if images is not None:
print("[INFO] stitching image")
stitcher = cv2.Stitcher_create()
(status, stitched) = stitcher.stitch(images)
# if the status is '0', then OpenCV successfully performed image
# stitching
if status == 0:
# write the output stitched image to disk
cv2.imwrite(args["output"], stitched)
# display the output stitched image to our screen
# cv2.imshow("Stitched", stitched)
# cv2.waitKey(0)
# otherwise the stitching failed, likely due to not enough keypoints)
# being detected
else:
print("[INFO] image stitching failed ({})".format(status))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment