Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort Matrix in OpenCV

Tags:

c++

opencv

I'm having trouble using cv::sort functionality in C++ API of OpenCV.

I'm trying to sort cv::Mat contents in OpenCV using

cv::sort(InputArray src, OutputArray dst, int flags);

The following code gives me a compilation error. I'm not sure whats wrong with this code:

using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
    Mat matrix(5,5,CV_32F,Scalar(0)),m;
    randn(matrix, 2.00, 1.00);
    cout<<"before sorting:\n"<<matrix<<endl;
    sort(matrix, m, CV_SORT_EVERY_ROW + CV_SORT_ASCENDING);
    cout<<"after sorting:\n"<<m<<endl;
    return 0;
}
like image 950
garak Avatar asked Feb 20 '23 21:02

garak


1 Answers

You have to use cv::sort() rather than sort(), even you are using namespace cv. That is because C++ has an implementation of sort() in namespace std and simply using sort() will make a conflict.

like image 55
Happy Lun Avatar answered Feb 23 '23 09:02

Happy Lun