Ask Your Question

Copy Multidimensional Matrix

asked 2016-12-16 10:17:04 -0500

atp gravatar image

Let's say I have a nxnx3 matrix and I want to copy that matrix into a nxnx5 matrix (and fill the remaining channels with other stuff). How can this be done in OpenCV? I'm looking for a solution that is not using a for loop.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-12-16 10:40:03 -0500

LBerger gravatar image

Split and merge :

Mat x(5,5,CV_32FC3,Scalar(1,2,3));
Mat y=Mat::zeros(5,5,CV_32FC(5));
vector<Mat> xPlan,yPlan;
cout << "x =" << x << "\n";
cout << "y =" << y << "\n";
cout << "y =" << y << "\n";
edit flag offensive delete link more


Interesting. I was not aware of CV_32FC(k) to create a matrix with k channels. I created a multidimensional matrix using:

int sizes[3] = {100, 100, 5};
cv::Mat img(3, sizes, CV_32F);

Would your code work in this case as well?

atp gravatar imageatp ( 2016-12-16 12:29:10 -0500 )edit

for 3d arrays I don't think opencv is ready. You can read this post

LBerger gravatar imageLBerger ( 2016-12-16 12:59:10 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-12-16 10:17:04 -0500

Seen: 165 times

Last updated: Dec 16 '16