How to convert MatOfPoint to MatOfPoint2f in opencv java api

前端 未结 3 1195
误落风尘
误落风尘 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条回答
  •  再見小時候
    2020-12-07 23:42

    MatOfPoint2f differs from MatOfPoint only in the type of the elements (32-bit float and 32-bit int respectively). The viable option (though with a performance penalty) is to create MatOfPoint2f instance and set its elements (in a loop) to be equal to the elements of of the source MatOfPoint.

    There are

     public void fromArray(Point... lp);
     public Point[] toArray();
    

    methods in both of the classes.

    So you can do just

     /// Source variable
     MatOfPoint SrcMtx;
    
     /// New variable
     MatOfPoint2f  NewMtx = new MatOfPoint2f( SrcMtx.toArray() );
    

提交回复
热议问题