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'm using:
Mat img_object = imread(patternImageName);
Mat a;
for (int index = 0,j = 0; index < img_object.rows; index = index + 2, j++)
{
a.row(j) = img_object.row(index);
}
But it throws the following exception:
OpenCV Error: Assertion failed (m.dims >= 2) in Mat, file /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/matrix.cpp, line 269
terminate called after throwing an instance of 'cv::Exception'
I could finally do it. Here is the solution
You can abuse resize() function:
resize() function will create new image, whose size is half of the original image.
INTER_NEAREST means that the values of small image will be calculated by "nearest neighbor" approach. In this specific case it means that value of pixel at position (1,2) in small image will be taken from pixel at position (2,4) in big image.