如何使用openCV(java)从最佳匹配列表中获取像素坐标?

如何使用openCV(java)从最佳匹配列表中获取像素坐标?,java,opencv,image-processing,feature-detection,feature-descriptor,Java,Opencv,Image Processing,Feature Detection,Feature Descriptor,我正在使用openCV java,我有一个最佳匹配列表。这是我的密码: final MatOfKeyPoint keyPoints1 = new MatOfKeyPoint(); final MatOfKeyPoint keyPoints2 = new MatOfKeyPoint(); ... MatOfDMatch matches = new MatOfDMatch(); ... List<DMatch> matchesList = matches.toLi

我正在使用openCV java,我有一个最佳匹配列表。这是我的密码:

  final MatOfKeyPoint keyPoints1 = new MatOfKeyPoint();
  final MatOfKeyPoint keyPoints2 = new MatOfKeyPoint();
  ...
  MatOfDMatch matches = new MatOfDMatch();
  ...
  List<DMatch> matchesList = matches.toList();
  List<DMatch> bestMatches = new ArrayList<DMatch>();

    for (int i = 0; i < matchesList.size(); i++)
        {
            Double dist = (double) matchesList.get(i).distance;

            if (dist < threshold)
            {
                bestMatches.add(matches.toList().get(i));
            }
        }
如何找到像素坐标

LinkedList<Point> queryList = new LinkedList<Point>();
LinkedList<Point> trainList = new LinkedList<Point>();

List<KeyPoint> keypoints_queryList = keyPoints1.toList();
List<KeyPoint> keypoints_trainList = keyPoints2.toList();

for (int i = 0; i < bestMatches.size(); i++) {
   queryList.addLast(keypoints_queryList.get(bestMatches.get(i).queryIdx).pt);
   trainList.addLast(keypoints_trainList.get(bestMatches.get(i).trainIdx).pt);
}


MatOfPoint2f queryCoords = new MatOfPoint2f();
queryCoords.fromList(queryList);

MatOfPoint2f trainCoords = new MatOfPoint2f();
trainCoords.fromList(trainList);

希望这有帮助

谢谢你,这确实帮了大忙!但是,为什么要在MatOfPoint2f中导入LinkedList?如果我直接在LinkedList上迭代不是更好吗?还有,你能再帮我一点忙吗?我基本上需要在所有这些坐标中选择一个点,并在这些坐标处执行触摸事件。如果图像1包含图像2的类似子集版本,例如instagram应用程序图标,我希望在instagram应用程序所在的坐标处执行触摸事件。使用MatofPoint2f的想法是在需要时使用它建立单应性。关于你的第二个问题,你能分享一些图片吗。在图像之间建立单应性时,将获得两个图像之间坐标映射的输出。您可以使用它提取感兴趣的区域,然后用边框或您选择的任何形状标记该区域,以帮助执行触摸事件。谢谢!我能够得到我感兴趣的区域,用一个边框标记该区域,并执行触摸事件。我使用模板匹配,而不是BRISK关键点检测器和描述符提取器。但现在我的问题是,我不知道如何调整阈值,因为即使我的代码正确地标记匹配区域,有时也会标记一个随机矩形,即使两幅图像没有真正的匹配。我提出了一个新问题:
LinkedList<Point> queryList = new LinkedList<Point>();
LinkedList<Point> trainList = new LinkedList<Point>();

List<KeyPoint> keypoints_queryList = keyPoints1.toList();
List<KeyPoint> keypoints_trainList = keyPoints2.toList();

for (int i = 0; i < bestMatches.size(); i++) {
   queryList.addLast(keypoints_queryList.get(bestMatches.get(i).queryIdx).pt);
   trainList.addLast(keypoints_trainList.get(bestMatches.get(i).trainIdx).pt);
}


MatOfPoint2f queryCoords = new MatOfPoint2f();
queryCoords.fromList(queryList);

MatOfPoint2f trainCoords = new MatOfPoint2f();
trainCoords.fromList(trainList);