Ask Your Question
-1

Java convert MatOfPoint in MatOfPoint2f

asked 2014-07-04 07:19:23 -0600

bbx gravatar image

updated 2014-07-04 07:37:02 -0600

Hello everybody... i am trying to convert an ArrayList(MatOfPoint) to an Arraylist(MatOfPoint2). Tried it with Arraylist.Add() and LinkedList.Addlast(). Same results :/ I make something wrong and iam blind of work at these lines :)

Since now i used:

Code :

//---------- Code
0   // Convert to MatofPoint2f
1   for(int i=0; i<contours.size(); i++){
2   contours.get(i).convertTo(mat2f, CvType.CV_32FC1);
3   System.out.println("Data : " + mat2f + " at Index : " + i);
4   contours2f.add(mat2f);
//---------

When i put the value of mat2f out on console ( line 3) , the values are correct like here for example :

//---------- Output of mat2f
Data : Mat [ 136*1*CV_32FC2, isCont=true, isSubmat=false, nativeObj=0x15bec140, dataAddr=0x15a31e30 ] at Index : 0
Data : Mat [ 156*1*CV_32FC2, isCont=true, isSubmat=false, nativeObj=0x15bec140, dataAddr=0x15a31e30 ] at Index : 1
Data : Mat [ 226*1*CV_32FC2, isCont=true, isSubmat=false, nativeObj=0x15bec140, dataAddr=0x15a31e30 ] at Index : 2
//---------

But when i try to Add them to the ArrayList contours2f ( line4 ). The output will be not the same. it seems so that inside, the same object is on every index. Please look here :

//-------- Output of contours2f that is type of ArrayList<MatOfPoint2f>
Mat [ 82*1*CV_32FC2, isCont=true, isSubmat=false, nativeObj=0x15bec140, dataAddr=0x15a38ce0 ] at Index : 0
Mat [ 82*1*CV_32FC2, isCont=true, isSubmat=false, nativeObj=0x15bec140, dataAddr=0x15a38ce0 ] at Index : 1
Mat [ 82*1*CV_32FC2, isCont=true, isSubmat=false, nativeObj=0x15bec140, dataAddr=0x15a38ce0 ] at Index : 2
Mat [ 82*1*CV_32FC2, isCont=true, isSubmat=false, nativeObj=0x15bec140, dataAddr=0x15a38ce0 ] at Index : 3
//-------

Maybe someone can help me ? I go crazy

Best regards and thanks for any help... bbx

--Update Added a picture from debugging. On the picture you can see the values of contours and the first 3 values of contours2f. I do not unterstand it :/

Debug Picture image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-07-16 10:34:17 -0600

AbbeFaria gravatar image

Hey, here's my solution to convert between the two:

List<MatOfPoints> data = new ArrayList<MatOfPoints>();
List<MatOfPoint2f> matrix = new ArrayList<MatOfPoint2f>();

Imgproc.findCountours(src,data,new Mat(),Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);

for(int i = 0; i < data.size(); i++){
    MatOfPoint2f myPt = new MatOfPoint2f();
    data.get(i).convertTo(myPt, CvType.CV_32FC2);
    matrix.add(myPt);
}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-07-04 07:19:23 -0600

Seen: 4,010 times

Last updated: Jul 16 '14