copy even rows/cols to another Mat
I would like to get the even rows/cols of a mat of 3 channels, something like this:
A = 1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
result = 1 1 1
1 1 1
How to can I do this using openCV?
Thanks in advance.
EDITED:
Here is the code I could integrate:
Mat img_object = imread(patternImageName);
Mat B;
for (int i = 0; i < img_object.cols; i += 2)
{
B.push_back(img_object.col(i));
}
// now we got 1 large 1d flat (column) array with all the collected elements,
// let's make a 3x3 Mat of it again:
B = B.reshape(-1,3);// 1 elem per channel, 3 rows.
B = B.t(); // transpose it
Mat B2;
for (int i = 0; i < B.rows; i += 2)
{
B2.push_back(B.row(i));
}
imwrite("as.png",B2);
But it throws the following expection:
OpenCV Error: Assertion failed (src.dims <= 2 && esz <= (size_t)32) in transpose, file /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/matrix.cpp, line 2007
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/matrix.cpp:2007: error: (-215) src.dims <= 2 && esz <= (size_t)32 in function transpose
Am I missing something?
Do you mean the value for the 3 channels at each even/even position or do you mean something weird like "even byte"?
maystroh, this is not matlab, we start indexing at 0 in c++, so you're already 'one-off', hee
I'm not quite sure if it works, but you could have luck with cv::resize and the INTER_NEAREST (or maybe INTER_AREA) flags. A different approach would be cv::remap with two custom created maps.