如何将Point添加到MatOfPoint2f?

时间:2013-03-31 02:12:28

标签: android opencv

我的目标是通过使用两个图像中的匹配关键点来计算基本矩阵。现在我得到了很好的匹配点:

MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptor1,descriptor2, matches);

List<DMatch> matchesList = matches.toList();
List<DMatch> good_matches = new ArrayList<DMatch>();
org.opencv.core.Point pt1;
org.opencv.core.Point pt2;

//Then I definite good_dist here
//....


for(int i =0;i<matchesList.size(); i++)
 {
  if(matchesList.get(i).distance<good_dist)
  {
     good_matches.add(matchesList.get(i));
     pt1 = keypoints1.toList().get(matchesList.get(i).queryIdx).pt; 
     pt2 = keypoints2.toList().get(matchesList.get(i).trainIdx).pt;
  }
}

现在我想将pt1和pt2传递给MatOfPoint2f以调用该函数:

Calib3d.findFundamentalMat(pt1, pt2, Calib3d.FM_8POINT);

有谁知道我该怎么办? 提前谢谢!

2 个答案:

答案 0 :(得分:4)

创建点数组(array_point)并执行下一步:

MatOfPoint2f yourArray_of_MatofPoint2f= new MatOfPoint2f(array_point);

这是来自Java,如果这不起作用,请发帖。

答案 1 :(得分:0)

所以我们有效地从List<DMatch> good_matches开始。然后,您需要将pt1和pt2 Point对象添加到“(matchesList.get(i).distance<good_dist)”if语句内的列表中,如List<org.opencv.core.Point>中所示。然后我们

List<DMatch> good_matches;
List<org.opencv.core.Point> points1;
List<org.opencv.core.Point> points2;

然后,我们将点列表转换为MatOfPoint2f,如下所示:

org.opencv.core.Point goodPointArray1[] = new org.opencv.core.Point[goodKeyPoints1.size()];
goodKeyPoints1.toArray(goodPointArray1);
MatOfPoint2f keypoints1Mat2f = new MatOfPoint2f(goodPointArray1);

我相信更有效的方法可以做到这一点,我很乐意听到它们