Ask Your Question
0

Convert several 1D mat to a single 2D mat in OpenCV

asked 2017-05-12 04:17:23 -0600

UsmanArif gravatar image

I am new to opencv. I have six 1200x1 Mat objects/variables. I want to make a single Mat variable which is 1200x6. How to do this? For example, i have six mat objects a,b,c,d,e,f of 1200x1 size and now i want to make A = [a,b,c,d,e,f] , which is 1200x6 size. Please help

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-05-12 04:33:44 -0600

berak gravatar image

updated 2017-05-12 04:35:36 -0600

assuming, all your 1d Mat's have the same num of columns, cv::Mat has a convenient push_back() function:

Mat large; // initially empty, type and size will get determined by push_back.
large.push_back(a);
large.push_back(b);
large.push_back(c);
large.push_back(d);
large.push_back(e);
large.push_back(f);

also, there's hconcat() and vconcat():

Mat large = a.clone(); // clone(), if you want to leave a intact
vconcat(large, b, large);
vconcat(large, c, large);
vconcat(large, d, large);
vconcat(large, e, large);
vconcat(large, f, large);
edit flag offensive delete link more

Comments

1

Thanks alot, really appreciated, I was stuck in it since last two days

UsmanArif gravatar imageUsmanArif ( 2017-05-12 06:05:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-12 04:17:23 -0600

Seen: 353 times

Last updated: May 12 '17