Ask Your Question
0

The opencv Mat object (java)

asked 2015-03-13 02:49:58 -0600

Nawara gravatar image

updated 2015-03-13 07:23:58 -0600

I'am new to opencv I want to understand the opencv Mat class

For the get method

I try the first one int get(int row, int col, byte[] data) with this example

  Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
  System.out.println(mat.dump());
  byte[] data = new byte[mat.cols() * mat.rows() * (int)mat.elemSize()];
  System.out.println(data.length);-->9
  System.out.println( mat.get(0, 0, data)); -->9

but I can't understand

1) the role of the third argument byte[] data

2) and the result

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-03-13 04:59:13 -0600

The array "data" gives you the result of a single element of the Mat object. Thus, your initialization is wrong:

byte[] data = new byte[(int)mat.elemSize()];

However, if you're using a Mat with a single channel only you may also ignore the array:

System.out.println(mat.get(0, 0, new byte[(int) mat.elemSize()]));

edit flag offensive delete link more

Comments

sorry, but you're wrong about this.

mat.get(0, 0, data) retrieves as many bytes as you allocate.

if you have an array of mat.elemSize(), it will retrieve a single element, if you have mat.elemSize() * mat.total() bytes, it will retrieve the whole Mat content.

e.g, a Mat(3,3,CV_32F) will have 3x3x4 bytes, and a Mat(3,3,CV_8UC3) will have 3x3x3 bytes.

berak gravatar imageberak ( 2015-03-13 06:08:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-03-13 02:49:58 -0600

Seen: 293 times

Last updated: Mar 13 '15