How to convert MatOfPoint to MatOfPoint2f in opencv java api

前端 未结 3 1193
误落风尘
误落风尘 2020-12-07 23:01

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_

3条回答
  •  Happy的楠姐
    2020-12-07 23:31

    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.

提交回复
热议问题