Changing color space in opencv without changing color of the image
Hi, I am working on a project where I read an image load the data into Mat data type. The I do some operations on it. All my operations are done assuming the color space is RGB (BGR as opencv stores in that way). Everuything is working fine. I was doing experiment on converting the output image to YUV format. But when I transform the output image from BGR2YUV using the following command cvtColor(img,out,CV_RGB2YCrCb); I found that the resulting image color is changed completely.
How can I change the color space from RGB to YUV without changing the colors in the image? For example, my output RGB image is green. WHen I convert this to YUV format and show the resulting image I found it blue and NOT green. I want a way to convert so that the output also become green.
"WHen I convert this to YUV format and show the resulting image I found it blue and NOT green."
don't worry, that's the expected result. if you convert it back, it will look all normal again.
Actually, like Pedro already suggested, you are misinterpreting the color channels of OpenCV. OpenCV assumes and uses BGR color channels, while you are focussing on RGB color channels. The mixup is completely normal :)