1

I found How to get pixel coordinates from Feature Matching in OpenCV Python to extract matched features coordinates and How to draw a line on an image in OpenCV? to draw lines b/w the two points as in the attached image. I am not getting how to use this in my case.

    from skimage.segmentation import slic
    from skimage.segmentation import mark_boundaries
    from skimage.util import img_as_float
    from skimage import io
    import matplotlib.pyplot as plt
    import cv2
    import numpy as np
    image=cv2.imread('C:\\Users\\pragyan.prakash\\001_F.png')
    segments = slic(img_as_float(image), n_segments = 100, sigma = 5)
    fig = plt.figure("Superpixels")
    ax = fig.add_subplot(1, 1, 1)
    ax.imshow(mark_boundaries(img_as_float(cv2.cvtColor(image, 
    cv2.COLOR_BGR2RGB)), segments))
    plt.axis("off")
    plt.show()
    feature=[]
    # loop over the unique segment values
    for (i, segVal) in enumerate(np.unique(segments)):
    # construct a mask for the segment
        mask = np.zeros(image.shape[:2], dtype = "uint8")
        mask[segments == segVal] = 255
        img=cv2.bitwise_and(image, image, mask = mask)
        feature.append(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))
        cv2.waitKey(0)
    orb = cv2.ORB_create()
    key=[];desc=[];sel= [];
    for i in feature:
        kp,des=orb.detectAndCompute(i,None)
        if des is not None: 
            key.append(kp)
            desc.append(des)
            sel.append(i)
    # create BFMatcher object
    bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
    match=[];pairs = [];
    for i in range(len(desc)):
        for j in range(len(desc)):
            #print (i,j)
            if i!=j:
                match.append(bf.match(desc[i],desc[j]))
                pairs.append((i,j))
    sorted_match=[]
    for i in match:
        sorted_match.append(sorted(i,key=lambda x:x.distance))

enter image description here

Pragyan
  • 567
  • 1
  • 5
  • 18
  • Well, welcome. Can you be more specific of what's your actual problem is? Also do you want to match 2 different images or features in a single image? – Eypros Mar 25 '19 at 12:17
  • I am trying to implement this paper https://rd.springer.com/chapter/10.1007/978-3-319-68505-2_6,i want to match feature in the single image – Pragyan Mar 25 '19 at 12:31
  • The link seems broken. Can you check it or provide another one? – Eypros Mar 25 '19 at 13:16
  • https://rd.springer.com/chapter/10.1007/978-3-319-68505-2_6 – Pragyan Mar 25 '19 at 14:10
  • Hi Eypros ,i updated the code and question,please have a look at it https://stackoverflow.com/questions/55339719/how-to-apply-ransac-on-segments-and-plotting-them – Pragyan Mar 25 '19 at 14:12

0 Answers0