Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Considering also @tuannhtn answer and playing a bit around I managed to achieve the in between cols/rows removal by the following code:

Mat a = (Mat_<int>(5, 5) << 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);

cout << endl << a << endl;

[1, 2, 3, 4, 5; 7, 8, 9, 10, 11; 12, 13, 14, 15, 16; 17, 18, 19, 20, 21; 22, 23, 24, 25, 26]

Mat b, c;

a(Range(0, a.rows - 2), Range(0, a.cols)).copyTo(b); a(Range(a.rows - 1, a.rows), Range(0, a.cols)).copyTo(c);

vconcat(b, c, b); cout << endl << b <<endl;< p="">

[1, 2, 3, 4, 5; 7, 8, 9, 10, 11; 12, 13, 14, 15, 16; 22, 23, 24, 25, 26]

Mat d, e; a(Range(0, a.rows), Range(0, a.cols - 3)).copyTo(d); a(Range(0, a.rows), Range(a.cols - 2, a.cols)).copyTo(e);

hconcat(d, e, d); cout << endl << d <<endl;< p="">

[1, 2, 4, 5; 7, 8, 10, 11; 12, 13, 15, 16; 17, 18, 20, 21; 22, 23, 25, 26]

Considering also @tuannhtn answer and playing a bit around I managed to achieve the in between cols/rows removal by the following code:

Mat a = (Mat_<int>(5, 5) << 1, 2, 3, 4, 5,
 7, 8, 9, 10, 11,
 12, 13, 14, 15, 16,
 17, 18, 19, 20, 21,
 22, 23, 24, 25, 26);

26); cout << endl << a << endl;

endl; [1, 2, 3, 4, 5; 7, 8, 9, 10, 11; 12, 13, 14, 15, 16; 17, 18, 19, 20, 21; 22, 23, 24, 25, 26]

26] Mat b, c;

c; a(Range(0, a.rows - 2), Range(0, a.cols)).copyTo(b); a(Range(a.rows - 1, a.rows), Range(0, a.cols)).copyTo(c);

a.cols)).copyTo(c); vconcat(b, c, b); cout << endl << b <<endl;< p="">

<<endl; [1, 2, 3, 4, 5; 7, 8, 9, 10, 11; 12, 13, 14, 15, 16; 22, 23, 24, 25, 26]

26] Mat d, e; a(Range(0, a.rows), Range(0, a.cols - 3)).copyTo(d); a(Range(0, a.rows), Range(a.cols - 2, a.cols)).copyTo(e);

a.cols)).copyTo(e); hconcat(d, e, d); cout << endl << d <<endl;< p="">

<<endl; [1, 2, 4, 5; 7, 8, 10, 11; 12, 13, 15, 16; 17, 18, 20, 21; 22, 23, 25, 26]

26]