1 | initial version |
here's some code to illustrate it:
Mat_<float> m(3,3); m << 1,2,3,4,5,6,7,8,9;
cerr << m << endl;
[1, 2, 3; 4, 5, 6; 7, 8, 9]
cerr << m(0,1) << endl; 2 Mat_<float> m2 = m.reshape(0,9);
cerr << m2 << endl; [1; 2; 3; 4; 5; 6; 7; 8; 9]
cerr << m2(0,1) << endl;
OpenCV Error: Assertion failed ((unsigned)i1 < (unsigned)size.p[1]) in cv::Mat_<float>::operator (), file E:\code\opencv\build\install\include\opencv2/core/mat. inl.hpp, line 1602
2 | No.2 Revision |
your reshape is correct, but then, you seem to have trouble with different indexing conventions between c++ in general, and matlab.
please, when in doubt, you should run a debug build, a lot of important assertions are suppressed in release.
here's some code to illustrate it:
Mat_<float> m(3,3); m << 3 | No.3 Revision |
your reshape is correct, but then, you seem to have trouble with different indexing conventions between c++ in general, and matlab.
please, when in doubt, you should run a debug build, a lot of important assertions are suppressed in release.
here's some code to illustrate it:
Mat_<float> m(3,3); m << 1,2,3,4,5,6,7,8,9;
cerr << m << endl;
[1, 2, 3;
4, 5, 6;
7, 8, 9]
cerr << m(0,1) << endl;
2
Mat_<float> m2 = m.reshape(0,9);
cerr << m2 << endl;
[1;
2;
3;
4;
5;
6;
7;
8;
9]
// out of bounds:
cerr << m2(0,1) << endl;
OpenCV Error: Assertion failed ((unsigned)i1 < (unsigned)size.p[1]) in cv::Mat_<float>::operator (), file E:\code\opencv\build\install\include\opencv2/core/mat.
inl.hpp, line 1602
// this would be the correct way for a 1d col-mat:
cerr << m2(1,0) << endl;
2
4 | No.4 Revision |
your reshape is correct, but then, you seem to have trouble with different indexing conventions between c++ in general, and matlab.
please, when in doubt, you should run a debug build, a lot of important assertions are suppressed in release.
here's some code to illustrate it:
Mat_<float> m(3,3); m << 1,2,3,4,5,6,7,8,9;
cerr << m << endl;
[1, 2, 3;
4, 5, 6;
7, 8, 9]
cerr << m(0,1) << endl;
2
cerr << m(1,0) << endl;
4
Mat_<float> m2 = m.reshape(0,9);
cerr << m2 << endl;
[1;
2;
3;
4;
5;
6;
7;
8;
9]
// out of bounds:
cerr << m2(0,1) << endl;
OpenCV Error: Assertion failed ((unsigned)i1 < (unsigned)size.p[1]) in cv::Mat_<float>::operator (), file E:\code\opencv\build\install\include\opencv2/core/mat.
inl.hpp, line 1602
// this would be the correct way for a 1d col-mat:
cerr << m2(1,0) << endl;
2
5 | No.5 Revision |
your reshape is correct, but then, you seem to have trouble with different indexing conventions between c++ in general, and matlab.
please, when in doubt, you should run a debug build, a lot of important assertions are suppressed in release.
here's some code to illustrate it:
Mat_<float> m(3,3); m << 1,2,3,4,5,6,7,8,9;
cerr << m << endl;
[1, 2, 3;
4, 5, 6;
7, 8, 9]
cerr << m(0,1) << endl;
2
cerr << m(1,0) << endl;
4
Mat_<float> m2 = m.reshape(0,9);
cerr << m2 << endl;
[1;
2;
3;
4;
5;
6;
7;
8;
9]
// out of bounds:
cerr << m2(0,1) << endl;
OpenCV Error: Assertion failed ((unsigned)i1 < (unsigned)size.p[1]) in cv::Mat_<float>::operator (), file E:\code\opencv\build\install\include\opencv2/core/mat.
inl.hpp, line 1602
// this would be the correct way for a 1d col-mat:
cerr << m2(1,0) << endl;
2
it seems, you want the transposed mat reshaped:
Mat mt = m.t();
cerr << mt << endl;
[1, 4, 7;
2, 5, 8;
3, 6, 9]
cerr << mt.reshape(0,9) << endl;
[1;
4;
7;
2;
5;
8;
3;
6;
9]