How can I know if the image is in RGB or BGR format?

岁酱吖の 提交于 2019-12-23 09:36:16

问题


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.

update:

The type of the image I am using is either .jpg or .png


回答1:


If your image is a BufferedImage then you can ask for his type with getType(), and test against the several constants (see: BufferedImage).




回答2:


If you are reading in the image file, or you have access to the code that reads in the file, know it is:

  • BGR order if you used cv2.imread()
  • RGB order if you used 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 !




回答3:


When you use opencv (imread, VideoCapture), the images are loaded in the BGR color space.



来源:https://stackoverflow.com/questions/30802493/how-can-i-know-if-the-image-is-in-rgb-or-bgr-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!