Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

yes, with cv::sortIdx it shouldn't be too difficult and work similar to (I haven't tested it - but you should get the spirit):

//get first column
cv::Mat one = your_mat.col(0);
// sort the first column and save indices in dst
cv::Mat1i idx;
cv::sortIdx(one, idx, cv::CV_SORT_EVERY_COLUMN + cv::CV_SORT_ASCENDING);
// now build your final matrix
cv::Mat result(your_mat.rows, your_mat.cols, your_mat.type());
for(int y = 0; y < your_mat.rows; y++){
   your_mat.row(y).copyTo(result.row(idx(0,y)));
}

yes, with cv::sortIdx it shouldn't be too difficult and work similar to (I haven't tested it - but you should get the spirit):

//get first column
cv::Mat one = your_mat.col(0);
// sort the first column and save indices in dst
cv::Mat1i idx;
cv::sortIdx(one, idx, cv::CV_SORT_EVERY_COLUMN cv::SORT_EVERY_COLUMN + cv::CV_SORT_ASCENDING);
cv::SORT_ASCENDING);
// now build your final matrix
cv::Mat result(your_mat.rows, your_mat.cols, your_mat.type());
for(int y = 0; y < your_mat.rows; y++){
   your_mat.row(y).copyTo(result.row(idx(0,y)));
}