Reputation: 1
Is there any way to know in advance if an image used as an input to a system is in RGB or BGR format?
I am using OpenCV with java API and I would like to convert an input image into grayscale or L*a*b* color space, but in OpenCV you have to specify first whether the image you want to convert is in RGB or BGR.
The type of the image I am using is either .jpg
or .png
.
Upvotes: 21
Views: 42559
Reputation: 17900
If you are reading in the image file, or you have access to the code that reads in the file, know it is:
cv2.imread()
mpimg.imread()
(assuming import matplotlib.image as mpimg
) If you don't know how the file was opened, the accepted answer BufferedImage
is great for Java.
I would like to find a way to do the same in Python!
Upvotes: 27
Reputation: 509
When you use opencv (imread, VideoCapture), the images are loaded in the BGR color space.
Upvotes: 10
Reputation: 36391
If your image is a BufferedImage
then you can ask for his type with getType()
, and test against the several constants (see: BufferedImage).
Upvotes: 2