I have a 256*256*16
mat, symbolizing 16 256*256
pixel images. And I want to get the pixel information of specific image. This can be easily done in python and Matlab. But I don’t know how to implement in C++ and I haven’t found proper func in OpenCV. It seems the expression Mat B = A(cv::Range(0, 2), cv::Range(0, 2), 1)
is wrong.
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
using namespace cv;
int main()
{
int Dimensions[3] = {16, 16, 2};
auto A = cv::Mat(3, Dimensions, CV_8UC1);
for (int i = 0; i < Dimensions[2]; i++)
{
for (int j = 0; j < Dimensions[1]; j++)
{
for (int k = 0; k < Dimensions[0]; k++)
{
A.at<uchar>(k, j, i) = i + j + k;
}
}
}
Mat B = A(cv::Range(0, 2), cv::Range(0, 2), 1);
}