GECKO 1.0
Human-computer interface based on hand gesture recognition
int HandDetector::median ( cv::Mat &  ROI) [private]

Returns the median of the pixel's values.

{
    //-- Unroll the ROI
    std::vector<unsigned char> unrolled;

    for (int i = 0; i < ROI.cols; i++ )
        for( int j = 0; j < ROI.rows; j++)
             unrolled.push_back( ROI.at<unsigned char>(i, j) );

    //-- Sort the vector
    std::sort( unrolled.begin(), unrolled.end() );

    //-- Get the median
    if ( unrolled.size() % 2 != 0)
    {
        //-- Odd vector:
        return ceil( unrolled.at( (unrolled.size() -1 ) / 2) );
    }
    else
    {
        //-- Even vector:
        double mean = unrolled.at( unrolled.size() / 2 ) + unrolled.at( (unrolled.size() / 2 ) - 1 );
        mean /= 2;
        return ceil(mean);
    }
}
 All Classes Functions Variables