在OpenCV Python中通过蛮力匹配获取像素坐标

在OpenCV Python中通过蛮力匹配获取像素坐标,python,python-2.7,opencv,matching,Python,Python 2.7,Opencv,Matching,我想在Python中使用OpenCV获得查询和训练图像的像素坐标 代码是: 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 descr

我想在Python中使用OpenCV获得查询和训练图像的像素坐标

代码是:

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)
我想从每个DMatch对象中获取像素坐标


如何执行此操作?

您可以使用以下命令执行此操作:

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)
在哪里

m、 trainIdx—列车描述符中描述符的索引,以及 m、 queryIdx-查询描述符中描述符的索引
代码是-代码,问题是-???你能更清楚地解释问题是什么吗?“匹配”将提供一个DMatch对象列表。我想为查询图像和火车图像获取每个DMatch对象的像素坐标。基本上,我想知道图像的哪一部分与火车图像的哪一部分与查询图像的哪一部分相匹配。我想知道在像素坐标方面,图像的预定义部分在qimg中的何处