Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::sortIdx opencv 3.2

I want to sort a matrix' row and get the indexes as a result. Therefor I use the function cv::sortIdx.

For a row like [40, 30, 100, 110, 10] I would expect the index vector to be [2, 1, 3, 4, 0]. This is also what I want to get as a result. Is this a correct assumption? In my code I am getting [4, 1, 0, 2, 3].

Mat unsorted(1, 5, CV_32F);
unsorted.at<int>(0, 0) = 40;
unsorted.at<int>(0, 1) = 30;
unsorted.at<int>(0, 2) = 100;
unsorted.at<int>(0, 3) = 110;
unsorted.at<int>(0, 4) = 10;

Mat sorted;
cv::sortIdx(unsorted, sorted, SORT_EVERY_ROW + SORT_ASCENDING);

cout << sorted.at<int>(0, 0) << " " << sorted.at<int>(0, 1) << " " << sorted.at<int>(0, 2) << " " << sorted.at<int>(0, 3) << " " << sorted.at<int>(0, 4) << " " << endl;

Is this a bug (referring to https://github.com/opencv/opencv/issues/8941) or do I have a lack of understanding of sortIdx?