Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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
         1 1 1

How to can I do this using openCV?

Thanks in advance.

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
         1 1 1

How to can I do this using openCV?

Thanks in advance.

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?

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?