title: OpenCV Python Stitch unordered images
body: <p>I currently have built a stitching program that is able to stitch any number of images however they have to be of specific order which is a problem for my specific image sets (working with 1452 images). My goal is to create an unordered stitcher program. I am convinced that the issue takes place when I am physically (well virtually) stitching the images to one another. </p>
  
  <p>Here is code for my stitching (assume keypoints found are accurate as well as homography) </p>
  
  <pre><code>    def stitchMatches(self,image1,image2,homography):
      #gather x and y axis of images that will be stitched
      height1, width1 = image1.shape[0], image1.shape[1]
      height2, width2 = image2.shape[0], image2.shape[1]
      #create blank image that will be large enough to hold stitched image
      blank_image = np.zeros(((width1 + width2),(height1 + height2),3),np.uint8)
      #stitch image two into the resulting image while using blank_image 
      #to create a large enough frame for images
      result = cv2.warpPerspective((image1),homography,blank_image.shape[0:2])
      #numpy notation for slicing a matrix together allows you to see the image
      result[0:image2.shape[0], 0:image2.shape[1]] = image2
      return result
  </code></pre>
  
  <p>I believe the issue is with these two lines.</p>
  
  <pre><code>result = cv2.warpPerspective((image1),homography,blank_image.shape[0:2])
  result[0:image2.shape[0], 0:image2.shape[1]] = image2
  </code></pre>
  
  <p>When I run the code on an ordered image (image 1 is north east most)set this is the result.</p>
  
  <p><a href="https://i.stack.imgur.com/WmoMY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WmoMY.jpg" alt="Ordered Images"></a></p>
  
  <p>However when I run the images in the reverse order I get this result.</p>
  
  <p><a href="https://i.stack.imgur.com/Ysy7z.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ysy7z.jpg" alt="enter image description here"></a></p>
  
  <p>To my understanding, this is because I have set the resulting image shape to map to image 2 but haven't been able to develop a work around.</p>
  
  <p>Here is a photo of multiple images showing the same issue of the images getting cropped out.</p>
  
  <p><a href="https://i.stack.imgur.com/snxxF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/snxxF.jpg" alt="enter image description here"></a></p>
  
  <p>Any help is appreciated.</p>