Why the cvtColor don't work?
I am confusing,why this code don't work
mask = imread("mask.jpg")>200;
cvtColor(mask, red, COLOR_GRAY2BGR);
It cannot run normally and will pop an abort window.But if I specify the color space when load the mask like
mask1 = imread("mask.jpg",IMREAD_GRAYSCALE)>200;
cvtColor(mask1, red, COLOR_GRAY2BGR);
Then the code is work well. I think this problem is result to the mask
is not grayscale image. But how to know the color space of a image in OpenCV?
This is my image mask.
Check number of channels : Mat::channels
@Ziri Such as the channels is 3,but it can be BGR,RGB,HSV or other something..
Yes. you' ll be able to tell if image is (GRAY/BINARY) or (Color). You can't tell if its RGB , HSV ..... using Opencv. if you load color image its BGR by default.
In this case you have to reformulate your question as well : How to find color space of an image ?
@Ziri You think the color space of the
mask
is grayscale or binary?If I want to change it into BGR.I should useCOLOR_GRAY2BGR
orCOLOR_Binary2BGR
?And I cannot find theCOLOR_Binary2BGR
cvtColor crashes because you're trying to convert color to color using COLOR_GRAY2BGR . if you use COLOR_GRAY2BGR , source image should be (GRAY or Binary 1 channel) and you can make sure using Mat::channels. What matters for cvtColor is the number of channels not color space.