I have a 3D vector and a number of images.I am trying to save the pixel data of the images into this vector. The first parameter contains the order number of the image in the set and the next two parameters should contain the pixel data at (x,y) location. Considering that I wrote the below code:-
Mat out;// out has an image in it
vector <vector< vector< int> >> Input_bin;
Input_bin.push_back(vector<vector<int>>(inst_num));// the order number
for (int i = 0; i <= out.cols; i++)
{
for (int j = 0; j <= out.rows; j++)
{
Input_bin[inst_num].push_back(vector<int>(out.at<int>(i,0)));
Input_bin[inst_num][out.at<int>(i,0)].push_back(out.at<int>(0,j));
}
}
But I am getting an error:
OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si ze.p[0] && (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * cha nnels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file C:\opencv_3\opencv\bui ld\include\opencv2/core/mat.inl.hpp, line 894
and I cant even try to print result of the vector out in the cmd screen. Any suggestions?
Edit 2- I tried another code by making the input_bin vector two-dimensional and float datatype
for (int i = 0; i <= out.cols; i++)
{
for (int j = 0; j <= out.rows; j++)
{
Input_bin[inst_num][out.at<float>(i, j)];
}}
still the same error
CV_32SC1
because you useint
) you are trying to access the Mat in the wrong order:out.at<int>(i,0)
means ROW i, COLUMN 0, but youri
variable loops over column andj
loops over row. – Micka