简体   繁体   中英

Get pixel coordinates from Brute Force Matching in OpenCV Python

I would like to get pixel coordinates of query and train image using OpenCV in Python.

The code is:

import numpy as np
import cv2

img1 = cv2.imread('qimg.png',0)          # queryImage
img2 = cv2.imread('timg.png',0)          # trainImage

# Initiate SIFT detector
orb = cv2.ORB()

# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)

# create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

# Match descriptors.
matches = bf.match(des1,des2)

I want to get the pixel coordinates from each DMatch object.

How do I do that?

You can do it using commands:

src_pts = np.float32([ kp1[m.queryIdx].pt for m in matches ]).reshape(-1,1,2)
dst_pts = np.float32([ kp2[m.trainIdx].pt for m in matches ]).reshape(-1,1,2)

Where

  • m.trainIdx - Index of the descriptor in train descriptors and
  • m.queryIdx - Index of the descriptor in query descriptors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM