1 | initial version |
If I have understood you correctly you'd like to have the rows specified in your ind-matrix in a new matrix. You need to use the 'row()' and 'col()'-Functions and copy them to the B-matrix which need to be initialized beforehand.
Taking your example above and assuming ind-matrix is a nx1-matrix with your row-indices of type int:
cv::Mat B(ind.rows, A.cols, A.type()); for( int i = 0; i < ind.rows; i++ ){ cv::Mat from = A.row(ind.at<int>(i,0)); cv::Mat dest = B.row(i); from.copyTo(dest); }
Note: if you know your rows/ columns are continous you can use rowRange(), colRange().
2 | No.2 Revision |
If I have understood you correctly you'd like to have the rows specified in your ind-matrix in a new matrix. You need to use the 'row()' and 'col()'-Functions and copy them to the B-matrix which need to be initialized beforehand.
Taking your example above and assuming ind-matrix is a nx1-matrix with your row-indices of type int:
cv::Mat B(ind.rows, A.cols, A.type());
for( int i = 0; i < ind.rows; i++ ){
cv::Mat from = A.row(ind.at<int>(i,0));
cv::Mat dest = B.row(i);
from.copyTo(dest);
Note: if you know your rows/ columns are continous you can use rowRange(), colRange().