Detect color space of loaded image - android OpenCV

asked 2017-11-30 07:03:52 -0500

noamgot gravatar image

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...

edit retag flag offensive close merge delete

Comments

1

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 gravatar imageberak ( 2017-11-30 07:54:42 -0500 )edit

@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)...?

noamgot gravatar imagenoamgot ( 2017-11-30 12:16:12 -0500 )edit
2

again, if that came from an opencv function, like imread(), or from onCameraFrame(CvCameraViewFrame inputFrame), it's bgr(a)

berak gravatar imageberak ( 2017-11-30 13:02:49 -0500 )edit
1

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)?

noamgot gravatar imagenoamgot ( 2017-11-30 15:07:36 -0500 )edit

yep that is correct as far as i see

StevenPuttemans gravatar imageStevenPuttemans ( 2017-12-01 08:00:31 -0500 )edit
1

weird as it is, Core.BitmapToMat() converts to RGBA

berak gravatar imageberak ( 2017-12-01 08:16:09 -0500 )edit