Why OpenCV Using BGR Colour Space Instead of RGB - zhongguogu/python GitHub Wiki
The reason why the early developers at OpenCV chose BGR color format is probably that back then BGR color format was popular among camera manufacturers and software providers. E.g. in Windows, when specifying color value using COLORREF they use the BGR format 0x00bbggrr.
BGR was a choice made for historical reasons and now we have to live with it. In other words, BGR is the horse’s ass in OpenCV."
OpenCV的早期开发人员选择BGR彩色格式的原因可能是当时BGR彩色格式在相机制造商和软件提供商中很流行。 例如。 在Windows中,当使用COLORREF指定颜色值时,它们使用BGR格式0x00bbggrr。
BGR是出于历史原因而做出的选择,现在我们必须忍受它。 换句话说,BGR是OpenCV中的佼佼者。
https://stackoverflow.com/questions/14556545/why-opencv-using-bgr-colour-space-instead-of-rgb
img = cv2.imread('path_to_image') img = img[:,:,::-1] Thanks @Patrick Artner for the exposition, makes things clear! Also, I was unaware until now that OpenCV reads images as [width, height, channels]. You sliced the wrong part of the image array.
Images consist of X,Y and BGR values. By slicing the last index you only inverteded the BGR to RGB.
To mirror the image you need to reverse either the X or the Y cooords wich are the indexes on 0 and 1 of the image - index 2 is RGB:
img = img[: ,: ,::-1] # reverses BGR to RGB, keeps x and y as is Instead you do
img = img[: ,::-1 ,: ] # reverses the x coords - mirror on x img = img[::-1 ,: ,: ] # reverses the y coords - mirror on y