# Aligning and stitching images based on defined feature using OpenCV

I would like to create a panoramic image by combining 2 images in which the same feature, a plus sign.

I've used cv2.xfeatures2d.SIFT_create() to find keypoints in the image however it doesn't find the plus symbol very well. Is there some way I can improve this by making it search specifically for a plus-shaped feature?

import cv2

sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(grey_image1, None)
kp_image = cv2.drawKeypoints(grey_image1, kp, None)

def showimage(image, name="No name given"):
cv2.imshow(name, image)
cv2.waitKey(0)
cv2.destroyAllWindows()
return

showimage(kp_image)


The source image is here, second image to align is here. Here is the resulting image from the code above. This is an example of the desired output made using GIMP and manually aligning the two images (the second image will need to transformed to fit properly).

NB I'm open to using other approaches outside of OpenCV/Python to solve this problem.

edit retag close merge delete

Have you tried to perform image registration? The code you provided is just a detector output. You have a small, yet sufficient number of feature points describing the plus sign. Were you able to detect keypoints on the second image and align them together? (use the function cv2.drawMatches() to see which keypoint match in a pair of images).