Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Access values from Mat

Hi
For example, I have a matrix M of size 10x10 and I have a column matrix ind of length 5
How can I assign A(ind,:) to a new matrix B in OpenCV?

Below is how I do in Matlab:

A = [ 41     8    33    36    22    14    38    43    18     4
    46    49     2     2    20    34    13    13    42     3
     7    48    43    14    39    33    26    41    30    27
    46    25    47     3    40     9    35    13    28    39
    32    41    34     5    10     6    45    47    46    47
     5     8    38    42    25    25    48    18    15     7
    14    22    38    35    23    48    28    10    38    29
    28    46    20    16    33    18     7    13    38    24
    48    40    33    48    36    30     8    31    20     1
    49    48     9     2    38    12    13    24    29    17]

ind = [2; 8; 4; 6; 2]  

B = A(ind, :);

B = [ 46    49     2     2    20    34    13    13    42     3
    28    46    20    16    33    18     7    13    38    24
    46    25    47     3    40     9    35    13    28    39
     5     8    38    42    25    25    48    18    15     7
    46    49     2     2    20    34    13    13    42     3]

Can anyone tell me how to do this in OpenCV without using for loop

Access values from Mat

Hi
For example, I have a matrix M of size 10x10 and I have a column matrix ind of length 5
How can I assign A(ind,:) to a new matrix B in C++ with OpenCV?

Below is how I do in Matlab:

A = [ 41     8    33    36    22    14    38    43    18     4
    46    49     2     2    20    34    13    13    42     3
     7    48    43    14    39    33    26    41    30    27
    46    25    47     3    40     9    35    13    28    39
    32    41    34     5    10     6    45    47    46    47
     5     8    38    42    25    25    48    18    15     7
    14    22    38    35    23    48    28    10    38    29
    28    46    20    16    33    18     7    13    38    24
    48    40    33    48    36    30     8    31    20     1
    49    48     9     2    38    12    13    24    29    17]

ind = [2; 8; 4; 6; 2]  

B = A(ind, :);

B = [ 46    49     2     2    20    34    13    13    42     3
    28    46    20    16    33    18     7    13    38    24
    46    25    47     3    40     9    35    13    28    39
     5     8    38    42    25    25    48    18    15     7
    46    49     2     2    20    34    13    13    42     3]

Can anyone tell me how to do this in C++ with OpenCV without using for loop