0

i was reading opencv related questions to study on the subject when stumbled across this curious question :

Stackoverflow Post

it's very interesting how chappjc (first answer) populates the Mat using a single loop. Since i often use opencv in conjunction with matlab i was wondering if there is a way to initialize the matrix by column without using the usual triple nested loop:

for (unsigned int k = 0; k < space[0]; k++)
        for (unsigned int i = 0; i < space[1]; i++)
            for (unsigned int j = 0; j < space[2]; j++)
                res_square.at<u_char>(i, j, k) = res_flat_vx[ (space[1]*space[2])*k + space[1]*j + i ];

So the result i was thinking of would be something like this :

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

Is it possible ?

Community
  • 1
  • 1
darkpirate
  • 712
  • 3
  • 10
  • 27

0 Answers0