1 | initial version |
We have in plans the creation of docs for Java-specific OpenCV classes.
For now let me share a short description of MatOfXxx
Java classes here:
MatOfXxx
classes (e.g. MatOfPoint
) were introduced to avoid redundant copying of intermediate data between Java and native memory.
E.g. you can get some large set of Points as the result of one OpenCV function and then pass it to another one.
In C++ we use std::vector<cv::Point>
for this. But use of ArrayList<org.opencv.core.Point>
in Java caused copying all the Points data from native OpenCV level to Java when returning these Points and copying them back when calling the next OpenCV function using them.
So for the sake of efficiency we switched to use of MatOfPoint
class in such cases that is a kind of Mat
of 1n or n1 dimensions that keeps a Point in each element (i.e. of type CV_32SC2 or CV_64FC2).
As you may know, Mat
keeps all the data on native level, so such objects can be passed between OpenCV calls without data copying.
But if in your Java code at some point you need direct access to actual Points data there are toArray()
and fromArray
methods to explicit transfer data to/from Java.
So turning back to your particular question, to create a MatOfPoint2f
containing the points corresponding to ones from existing MatOfKeyPoint
you need:
MatOfKeyPoint.toArray()
KeyPoint[]
and create a corresponding Point[]
(all of cv::Point
, cv::Point2f
and cv::Point2d
are represented as org.opencv.core.Point
in Java)MatOfPoint2f.fromArray()
or c-tor MatOfPoint2f(Point...pa)
to put your Points to native level