Ask Your Question
0

Copy Multidimensional Matrix

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

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
2

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

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";
split(x,xPlan);
split(y,yPlan);
xPlan.push_back(yPlan[3]);
xPlan.push_back(yPlan[4]);
merge(xPlan,y);
cout << "y =" << y << "\n";
edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 681 times

Last updated: Dec 16 '16