Ask Your Question

Tralala's profile - activity

2015-09-23 08:35:43 -0600 received badge  Enthusiast
2015-09-16 09:42:40 -0600 commented question OpenCV's Java bindings Mat.get() gives weird results

Well I recognise that, that's why I made this question in the first place. So the bottom line is you don't know why the provided code doesn't work?

2015-09-16 09:35:27 -0600 commented question OpenCV's Java bindings Mat.get() gives weird results

I don't see your point. That is one of the reasons I want to create the 2D array. I must convert it, so I can work with it easily in Java, without the sluggish JNI calls to individual pixels.

2015-09-16 09:20:04 -0600 received badge  Editor (source)
2015-09-16 09:19:12 -0600 commented question OpenCV's Java bindings Mat.get() gives weird results

This is not what i want. I want to create a 2D array.

2015-09-16 08:47:41 -0600 asked a question OpenCV's Java bindings Mat.get() gives weird results

I have a 8UC1 Mat image. I'm trying to convert it to Java 2D byte array with [x][y] coordinates. Here's what I have so far:

byte[][] arr = new byte[mat.cols()][mat.rows()];
for (int colIndex = 0; colIndex < mat.cols(); colIndex++) {
     mat.get(0, colIndex, arr[colIndex]);
 }

However, that gives me totally scrambled results. For example a mat with .dump() such as this:

[255, 255, 255, 255, 255, 255, 255, 255, 255, 255;
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
 255, 255, 255, 255, 255, 255, 255, 255, 255, 255;
 255, 255, 255, 255, 255, 255, 255, 255, 255, 255;
 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]

gives me this (don't mind the -1, that's OK):

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 
-1 -1 -1 -1 -1 -1 -1 -1 -1 0 
-1 -1 -1 -1 -1 -1 -1 -1 0 0 
-1 -1 -1 -1 -1 -1 -1 0 0 0 
-1 -1 -1 -1 -1 -1 0 0 0 0