Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It can also be done in this way like i got answer on SO here

Mat img = imread("messi5.jpg");
for(int i=0;i<img.rows;i++)
    for(int j=0;j<img.cols;j++) {
        cv::Vec3b p = img.at<cv::Vec3b>(i,j);
        for(int k = 0;k < img.channels();k++)
             p[k] = p[k] > 127 ? 255 : 0;
        img.at<cv::Vec3b>(i,j) = p;
}

But yes the above answer of @Berak is more appropriate and better