Matlab to OpenCV conversion

asked 2013-02-14 21:31:40 -0500

UserOpenCV gravatar image

I am converting Matlab code to OpenCV "C/cpp" code. And I have some doubts as below.

A = [ 2; 10;  7;  1;  3;  6; 10; 10;  2; 10];
ind = [10; 5; 9; 2];

B is a submatrix of A ; Elements of matrix B are elements of A at locations specified in ind.

B = [10 3; 2; 10];

In Matlab, I just use

B = A(ind);

In C using OpenCV,

for ( int i = 0; i < ind.rows; i++) {
    B.at<int>(i,0) = A.at<int>(ind.at<int>(i,0), 0);
}

Is there a way to do it without using for loop?

edit retag flag offensive close merge delete