Ask Your Question

Revision history [back]

May be something like this :

Mat x(32,64,CV_16UC1);
for (int i=0;i<x.rows;i++)
    for (int j=0;j<x.cols;j++)
        x.at<ushort>(i,j)=i+j;

Mat v;
cv::sort(x, v, CV_SORT_EVERY_ROW);
for (int i = 0; i < x.rows; i++)
{
     cout<<"Line "<<i<< "median = "<< v.at<ushort>( i,v.cols / 2) <<"\n";
}
cv::sort(x, v, CV_SORT_EVERY_COLUMN);
for (int j = 0; j < x.cols; j++)
{
    cout << "Col " << j << "median = " << v.at<ushort>(v.rows /2,j ) << "\n";
}