0

I have two images. For some specific points I know their coordinates on the two images, how can I draw lines between those points and plot a figure showing the two images along with the matching lines?

I actually didn't know where to start here. That's why I didn't show any code yet. Would matplotlib benefit me in this case?

EDIT This is an example of what I'm expecting (the image is taken from, here):

enter image description here

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • we should see how should **look** the expected result – RomanPerekhrest Nov 03 '17 at 14:27
  • Sure, I have added an example. – Simplicity Nov 03 '17 at 14:31
  • A good place to start might be to display your two images on two subplots. and make the connections with a [`ConnectionPatch`](https://matplotlib.org/api/_as_gen/matplotlib.patches.ConnectionPatch.html#matplotlib.patches.ConnectionPatch). You might want to give that a go and come back here with any questions you have if you can't get it working. – tmdavison Nov 03 '17 at 15:06

1 Answers1

-1

What you are searching for is directly in your example you just have to use the function. If you don't know what matches contains you can use the example and look into it.

 img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:20], flags=2,outImg = img1)

My full code:

if method is "ORB":
        #Compute keypoints for both images
        kp1,des1 = self.computeORB(img1)
        kp2,des2 = self.computeORB(img2)  
        #===================================================================
        # for i,j in zip(kp1,kp2):
        #     print("KP1:",i.pt)  
        #     print("KP2:",j.pt)   
        #===================================================================
        #use brute force matcher for matching descriptor1 and descriptor2
        bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
        # Match descriptors.
        matches = bf.match(des1,des2)

        # Sort them in the order of their distance.
        matches = sorted(matches, key = lambda x:x.distance)
        self.filterMatches(matches)

        # Draw first 10 matches.
        img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:20], flags=2,outImg = img1)

        #show result
        cv2.imshow("Matches",img3)
        cv2.waitKey(0)

def computeORB(self,img):
    #Initiate ORB detector
    orb = cv2.ORB_create()

    #find keypoints
    kp = orb.detect(img,None)

    #compute despriptor
    kp, des = orb.compute(img,kp)
    # draw only keypoints location,not size and orientation
    img2 = cv2.drawKeypoints(img, kp, None, color=(0,255,0), flags=0)
    #plt.imshow(img2), plt.show()

    return kp,des

note that you need cv2 contribution version if you are using newer python versions.

Max Krappmann
  • 490
  • 5
  • 19