I want to grayscale image in openCV

I am using video player.
I want to add grascale images to it.
so I write this code in draw function.
( ofVideoPlayer fingerMovie;)
(ofxCvColorImage img;)
ofPixels pixels = fingerMovie.getPixels();
img.setFromPixels(pixels);
cv::Mat mat=ofxCv::toCv(img);
cv::cvtColor(mat,mat,cv::COLOR_BGR2GRAY);
img.draw(400,20);

But I cannot get gray image.
Please tell me what is wrong with this.
I checked channels is changed 3->1 by cv::cvtColor
But it is not show gray image .why?

You probably need to call image.update() for it to upload the converted image to the graphics card

If you just want to convert a ofxCvColorImage to a ofxCvGrayscaleImage , you can simply use the overloaded = operator.
So basically like that:

// grayscale_img is a ofxCvGrayscaleImage
// color_img is a  ofxCvColorImage 
grayscale_img = color_img; // now you've a got a bw version

For more info, check this: https://openframeworks.cc///documentation/ofxOpenCv/ofxCvGrayscaleImage/

OK You are right.
Thank you vvzen

Today I found this problem’s true answer .
I lost
ofxCv::toOf(mat,m_colorimg.getPixels());
before draw.
When you lost it ,you will get Original+edited image in draw.(not pure edited image)
I think it is pure edited image.:joy: