可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 Lab* color space, and 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:
When you use opencv (imread, VideoCapture), the images are loaded in the BGR color space.
回答3:
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 !