Reputation: 235
I have a multi-dimensional matrix in OpenCV, for example like
Mat matrix(1,1,CV_64FC(100), Scalar(0));
I know it is very easy to access the 2d matrix in a multi-dimension matrix in Matlab, for example like matrix(:,:,1), matrix(:,:,100). But how should we do this in OpenCV? It's true that OpenCV can use at to access one element in the matrix, but how can we access a 2d matrix while fixing the channel? Thanks!
Upvotes: 1
Views: 1619
Reputation: 2575
Note there is difference between a multi-Channel Matrix and a multi-dimensional Matrix in OpenCV.
If you are interested in the latter here is an example that shows how to access each dimension for a 3d Matrix
Upvotes: 1
Reputation: 808
A simple way to do it would be the following
Mat matrix(1,1,CV_64FC(100), Scalar(0));
cv::vector<cv::Mat> channels;
cv::split(matrix,channels);
int i = 0;
cv::Mat channel_i = channels[i];
Pleae see docs split and maybe for more advanced manipulation mixChannels. (not used mixChannels myself)
Upvotes: 1