Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print opencv matrix content in Java

I have openCV matrix in Java and I would like to print out the content of it.I tried the toString() function as follows descriptor.toString() so I could achieve this form

"[[1,2,3,4],[4,5,6,7],[7,8,9,10]]"

where each array is the ith row in the matrix but I got the following result. I tried to remove the toString but still the same problem.

Mat [ 3*4*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x5dc93a48, dataAddr=0x5d5d35f0]

Where 3 is the number of rows and 4 is the number of columns.

Any help how can I get the matrix content?!

like image 590
omarsafwany Avatar asked May 18 '13 18:05

omarsafwany


2 Answers

It's not exactly as [[1,2,3,4],[4,5,6,7],[7,8,9,10]] but it works:

Mat freqs = Mat.zeros(10, 10, CvType.CV_32F);

// do math...

String dump = freqs.dump();
Log.d(TAG, dump);
like image 179
auraham Avatar answered Sep 26 '22 04:09

auraham


Code:

    int[][] testArray = new int[][]{{1,2,3,4},{4,5,6,7},{7,8,9,10}};
    Mat matArray = new Mat(3,4,CvType.CV_8UC1);
    for(int row=0;row<3;row++){
        for(int col=0;col<4;col++)
            matArray.put(row, col, testArray[row][col]);
    }
    System.out.println("Printing the matrix dump");
    System.out.println(matArray.dump());

Output:
Printing the matrix dump
[1, 2, 3, 4;
4, 5, 6, 7;
7, 8, 9, 10]

like image 26
comrench Avatar answered Sep 26 '22 04:09

comrench