I\'m trying to implement the example code of the following
question
by using opencv java api. To implement findContours(gray, contours, CV_RETR_LIST, CV_CHAIN_APPROX_
Although this question has already been answered, I believe that the accepted answer is not the best. Converting a matrix to an array and then back comes with quite the performance penalty, both time-wise and memory-wise.
Instead, OpenCV already has a function that does exactly this: convertTo.
MatOfPoint src;
// initialize src
MatOfPoint2f dst = new MatOfPoint2f();
src.convertTo(dst, CvType.CV_32F);
I have found this to be significantly faster and more memory-friendly.
To convert a MatOfPoint2f to a MatOfPoint, use CvType.CV_32S instead.