0

For a project I am working on I need to stitch a series of portrait photos into a 360 degree panorama. I have managed to stitch small segments of these series together (roughly 60 degrees), but have failed to stitch the whole series together. Upon inspection, I have noticed that opencv has been returning ERR_NEED_MORE_IMGS when trying to stitch between two consecutive segments. After some googling, I have found that it is likely because some of the photos in the series are very featureless, and therefore don't stitch very well.

I have searched the internet for a way to stitch these low feature images, but all I have found is OpenCV: Stitch images with few features.

I have also tried stitching frames from a video together to create the target 360 panorama, but that has also failed.

Here is my code so far:

import cv2
import argparse
import imutils
import numpy as np

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", type=str, required=True)
ap.add_argument("-o", "--output", type=str, required=True)
args = vars(ap.parse_args())

files = args['input'].split(",");
images = []

for f in files:
    images.append(cv2.imread(f))

stitcher = cv2.Stitcher_create()
(status, stitched) = stitcher.stitch(images)

if (status == 0):
    # Crop panorama to content
    stitched = cv2.copyMakeBorder(stitched, 10, 10, 10, 10, cv2.BORDER_CONSTANT, (0, 0, 0))
    gray = cv2.cvtColor(stitched, cv2.COLOR_BGR2GRAY)
    thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)[1]
    cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnts = imutils.grab_contours(cnts)
    c = max(cnts, key=cv2.contourArea)

    mask = np.zeros(thresh.shape, dtype="uint8")
    (x, y, w, h) = cv2.boundingRect(c)
    cv2.rectangle(mask, (x, y), (x + w, y + h), 255, -1)
    minRect = mask.copy()
    sub = mask.copy()

    while cv2.countNonZero(sub) > 0:
        minRect = cv2.erode(minRect, None)
        sub = cv2.subtract(minRect, thresh)

    cnts = cv2.findContours(minRect.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnts = imutils.grab_contours(cnts)
    c = max(cnts, key=cv2.contourArea)
    (x, y, w, h) = cv2.boundingRect(c)

    stitched = stitched[y:y + h, x:x + w]
    cv2.imwrite(args["output"], stitched)
else:
    raise Exception('Error stitching images', status)

Any help would be much appreciated

Sample picture 1: https://drive.google.com/file/d/1z7HHwLP6y-pcgcDzeJTutuYiv74U3foj/view?usp=sharing Sample picture 2: https://drive.google.com/file/d/1oCkQYgXUOjpe1kqxa0dQLgqAwoJazePf/view?usp=sharing

jptr21824
  • 63
  • 1
  • 5
  • pictures please. and mentally prepare yourself for the possibility that this may simply not be solvable. stitching consists of the estimation and the composition steps. if you have multiple fixed cameras, you can estimate the transformation once (calibration), and compose arbitrary input given that estimation. if your views aren't fixed, you'll have to estimate every time. – Christoph Rackwitz Feb 16 '22 at 12:23

0 Answers0