Ask Your Question
1

Adding row to Mat in Java

asked 2014-01-07 15:39:01 -0600

Rauluka gravatar image

updated 2014-01-08 03:41:23 -0600

berak gravatar image

I have a problem with adding rows to Mat. I use push_back method but I get error: Sizes of input arguments do not match. Of course my Mats have same column length as it is said in method description.

Mat test = new Mat(new Size(10,100),5);
Mat row = new Mat(new Size(1,100),5);
test.push_back(row);

^It will result in error which I described above. Do you have any ideas how insert a row to a matrix?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-01-08 01:04:53 -0600

Haris gravatar image

updated 2014-01-08 01:07:48 -0600

According to OpenCV Java API Documentation the constructor Mat(Size size, int type) creates Mat in cols X rows order like,

Mat(Size(cols, rows), int type)

So your code should be changed to

Mat test = new Mat(new Size(10,100),5); //create mat with 10 column and 100 rows
Mat row = new Mat(new Size(10,1),5); // create mat with 10 column and 1 rows
test.push_back(row);

or

Mat test = new Mat(new Size(100,10),5); //create mat with 100 column and 10 rows
Mat row = new Mat(new Size(100,1),5); // create mat with 100 column and 1 rows
test.push_back(row);
edit flag offensive delete link more

Comments

Yes, that's true. Unfortunately MatOfFloat while using dump() outpust e.g. [1,2,3] and it's size 1x3, co it is confusing. I did have to transponse it first.

Rauluka gravatar imageRauluka ( 2014-01-08 09:07:28 -0600 )edit

Question Tools

Stats

Asked: 2014-01-07 15:39:01 -0600

Seen: 2,860 times

Last updated: Jan 08 '14