How to add Point to MatOfPoint2f?

My goal is to calculate the main matrix using the corresponding key points from two images. Now I got good matches:

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 pt1 and pt2 to MatOfPoint2f to call the function:

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

Does anyone know what to do? Thanks in advance!

+4
source share
2 answers

Create an array of points ( array_point ) and do the following:

 MatOfPoint2f yourArray_of_MatofPoint2f= new MatOfPoint2f(array_point); 

This is from Java, if it does not work, send a message.

+4
source

So, we start with List<DMatch> good_matches . Then you want to add the pt1 and pt2 Point objects to the lists inside your statement " (matchesList.get(i).distance<good_dist) " if, as in List<org.opencv.core.Point> . Then we have

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

Then we convert the point lists 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 that more effective ways to do this exist, and I would like to hear them.

0
source

All Articles