Reputation: 73
My goal is to calculate the fundamental Matrix by using the matching keypoints from two images. Now I got the good matching points:
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;
}
}
Now I want to pass the pt1 and pt2 to MatOfPoint2f in order to call the function:
Calib3d.findFundamentalMat(pt1, pt2, Calib3d.FM_8POINT);
Does anyone know what should I do? Thanks in advance!
Upvotes: 4
Views: 3080
Reputation: 35
So we effectively start with List<DMatch> good_matches
. You then want to add your pt1 and pt2 Point objects to lists inside of your "(matchesList.get(i).distance<good_dist)
" if statement, as in List<org.opencv.core.Point>
. We then have
List<DMatch> good_matches;
List<org.opencv.core.Point> points1;
List<org.opencv.core.Point> points2;
We then convert the lists of points to MatOfPoint2f
as follows:
org.opencv.core.Point goodPointArray1[] = new org.opencv.core.Point[goodKeyPoints1.size()];
goodKeyPoints1.toArray(goodPointArray1);
MatOfPoint2f keypoints1Mat2f = new MatOfPoint2f(goodPointArray1);
I am sure more efficient ways of doing this exist, and I would love to hear them
Upvotes: 0
Reputation: 1049
Create Array of point (array_point
) and do next:
MatOfPoint2f yourArray_of_MatofPoint2f= new MatOfPoint2f(array_point);
This is from Java, if this doesn't work, please post.
Upvotes: 4