title: OpenCV image stitching with few features
body: <p>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.</p>
  <p>I have searched the internet for a way to stitch these low feature images, but all I have found is
  <a href="https://stackoverflow.com/questions/45505548/opencv-stitch-images-with-few-features">OpenCV: Stitch images with few features</a>.</p>
  <p>I have also tried stitching frames from a video together to create the target 360 panorama, but that has also failed.</p>
  <p>Here is my code so far:</p>
  <pre><code>import cv2
  import argparse
  import imutils
  import numpy as np
  
  ap = argparse.ArgumentParser()
  ap.add_argument(&quot;-i&quot;, &quot;--input&quot;, type=str, required=True)
  ap.add_argument(&quot;-o&quot;, &quot;--output&quot;, type=str, required=True)
  args = vars(ap.parse_args())
  
  files = args['input'].split(&quot;,&quot;);
  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=&quot;uint8&quot;)
      (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) &gt; 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[&quot;output&quot;], stitched)
  else:
      raise Exception('Error stitching images', status)
  </code></pre>
  <p>Any help would be much appreciated</p>
  <p>Sample picture 1: <a href="https://drive.google.com/file/d/1z7HHwLP6y-pcgcDzeJTutuYiv74U3foj/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1z7HHwLP6y-pcgcDzeJTutuYiv74U3foj/view?usp=sharing</a>
  Sample picture 2: <a href="https://drive.google.com/file/d/1oCkQYgXUOjpe1kqxa0dQLgqAwoJazePf/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1oCkQYgXUOjpe1kqxa0dQLgqAwoJazePf/view?usp=sharing</a></p>