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

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


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!