Detect color space of loaded image - android OpenCV
Hi I'm developing an Android app using OpenCV for Android. The app allows the user to load or shoot an image, and then performs some manipulations on it. My question is: how can I detect the color-space of the image? I never know whether it's RGB/BGR, or maybe RGBA/BGRA... Is there a way to know? It is crucial because I need to perform a color conversion (to LAB space), and the results will be significantly different depending the original color space of course...
in general, you can't. the Mat class does not know, what's inside.
but in general, you can assume, that anything you get from opencv is bgr(a), while if it's from android, it's rgba
@berak thanks for the comment. I'm not sure that I fully understood your last sentence - I'm using OpenCV4Android, so I should expect rgb(a) or bgr(a)...?
again, if that came from an opencv function, like
imread()
, or fromonCameraFrame(CvCameraViewFrame inputFrame)
, it's bgr(a)Just to make sure that I got it - in my case I get a Bitmap from a URI (image uploaded from the gallery, or shot by the user), and convert it to a Mat object (using Core.BitmapToMat() ). I should expect a RGB(A) then (because the image was not loaded by opencv function)?
yep that is correct as far as i see
weird as it is, Core.BitmapToMat() converts to RGBA