There is no direct way to extract random ordering of rows / columns without any iteration. The easiest way is to extract the rows and place them in the target matrix one by one. If you have the declared matrix A and its data set:
cv::Mat B; B.push_back(A(cv::Range(2,3),cv::Range::all())); B.push_back(A(cv::Range(8,9),cv::Range::all())); B.push_back(A(cv::Range(4,5),cv::Range::all())); B.push_back(A(cv::Range(6,7),cv::Range::all())); B.push_back(A(cv::Range(2,3),cv::Range::all()));
should do what you want. operator()(cv::rowRange, cv::colRange) used to retrieve selected rows.
source share