Code conversion in opencv C++
I am trying to convert this second answer code into c++ , What I did is not giving me appropriate result , here is my code :
{
Mat img = imread("messi5.jpg");
int level_n = 2;
Mat p = Mat::zeros(img.cols*img.rows, 3, CV_32F);
vector<Mat> bgr;
cv::split(img, bgr);
//Divide each pixel color with 127 for level 2
for(int i=0; i<img.cols*img.rows; i++) {
p.at<float>(i,0) = bgr[0].data[i] / 127.0;
p.at<float>(i,1) = bgr[1].data[i] / 127.0;
p.at<float>(i,2) = bgr[2].data[i] / 127.0;
}
vector<Mat> Img2 = p[bgr];
Mat out;
cv::transform(img,out,p);
imshow ("output" , out);
}
What I didn't understand is how I put these colour's which I divided by 127 into Matrix , where I am going wrong?
Other way i am trying is
vector<Mat> bgr;
Mat blue , green , red;
cv::split(img, bgr);
blue = bgr[0]/127.0;
if (blue > 128)
{
blue = 255;
}
else
{
blue = 0;
}
same for red and green
the 'special' case for level 2 is actually simple:
img = img > 127; // done ! ;)
but berak when i do it like
if (img = img>127) { img == 255 }
because i want to fix that value to 255 if its greater then 127 , but it show me error onif
yea, your if() is wrong.
don't take above too serious. though it works 'as is', it's more like the 1st answer, not the 'general' case
its done , thanks
but its
img=img
>=128; img == 255; img = img
<128; img == 0;
not giving me fruitfull result like themMat img = imread("messi5.jpg");
img = img > 127;
imshow("!",img);