# Is it possible to construct my own DMatch list in python?

**URL:** <https://forum.opencv.org/t/is-it-possible-to-construct-my-own-dmatch-list-in-python/10317>\
**Category:** Python\
**Tags:** features2d\
**Created:** [September 26, 2022, 10:03am UTC](https://forum.opencv.org/t/is-it-possible-to-construct-my-own-dmatch-list-in-python/10317 "2022-09-26T10:03:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Constantine](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@Constantine](https://forum.opencv.org/u/Constantine)\
**Post date:** [September 26, 2022, 10:03am UTC](https://forum.opencv.org/t/is-it-possible-to-construct-my-own-dmatch-list-in-python/10317/1 "2022-09-26T10:03:13Z")

</div>

I’ve done sift descriptor matching and RANSAC algorithm .  
Now i got a list of coordinates.  
I want to see if there’s a difference , cv.drawMatches() requires a list of DMatch data.  
I’m not sure if [This tutorial](https://docs.opencv.org/4.6.0/d1/de0/tutorial_py_feature_homography.html) did the same thing.

```auto
if len(good)>MIN_MATCH_COUNT:
    src_pts = np.float32([kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2)
    dst_pts = np.float32([kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2)
    M, mask = cv.findHomography(src_pts, dst_pts, cv.RANSAC,5.0)
    matchesMask = mask.ravel().tolist()
    h,w = img1.shape
    pts = np.float32([[0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)
    dst = cv.perspectiveTransform(pts,M)
    # why draw this line?
    img2 = cv.polylines(img2,[np.int32(dst)],True,255,3, cv.LINE_AA)
else:
    print( "Not enough matches are found - {}/{}".format(len(good), MIN_MATCH_COUNT) )
    matchesMask = None

draw_params = dict(matchColor = (0,255,0), # draw matches in green color
                   singlePointColor = None,
                   matchesMask = matchesMask, # draw only inliers
                   flags = 2)
img3 = cv.drawMatches(img1,kp1,img2,kp2,good,None,**draw_params)

```

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [September 26, 2022, 10:58am UTC](https://forum.opencv.org/t/is-it-possible-to-construct-my-own-dmatch-list-in-python/10317/2 "2022-09-26T10:58:07Z")

</div>

sure you can do that !

> [@Constantine](#):
>
> Now i got a list of coordinates.

that’s a bit useless here, you’ll need the _indices_ into the original keypoint lists (from detect()) (`m.queryIdx, m.trainIdx` in the ex.), also the distance (from ransac ?). then its a simple:

```
dm = []
for whatever:
  dm.append(cv2.DMatch(idx1, idx2, distance))

```

you also need a list of bools (inlier or not), `matchesMask` in the tutorial.

> [@Constantine](#):
>
> `# why draw this line?`

it’s the white box around the target in the right image, hard to see :}

---

<div class="post-metadata">

**Author:** ![Constantine](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@Constantine](https://forum.opencv.org/u/Constantine)\
**Post date:** [September 26, 2022, 11:10am UTC](https://forum.opencv.org/t/is-it-possible-to-construct-my-own-dmatch-list-in-python/10317/3 "2022-09-26T11:10:28Z")

</div>

Thanks again ! Exactly what i want !
