OpenCV giving an opposite color order (BGR - RGB) upon reading

515 Views Asked by At

According to the official documentation, reading an image using opencv decodes an in BGR order. But using the version (opencv-python==4.7.0.72), its returning the image in RGB order in a default mode.

import cv2
if __name__ == "__main__":
    image_path = '/home/dell/Downloads/God_Ganesha.jpg'

    image = cv2.imread(image_path)
    img_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    cv2.namedWindow('cv2 bgr', cv2.WINDOW_NORMAL)
    cv2.imshow('cv2 bgr', image)
    cv2.namedWindow('cv2 rgb', cv2.WINDOW_NORMAL)
    cv2.imshow('cv2 rgb', img_rgb)
    cv2.waitKey(0)

Reading an image using opencv should have returned the image in BGR order (official doc) but it's returning in RGB order, and when I did cv2.COLOR_BGR2RGB, it returned in BGR order. Opencv has not mentioned that their default has been changed into RGB. Is there anything I am missing here or error?

Screenshot of the image on both color order

1

There are 1 best solutions below

0
On

If you want to read , show image in open cv to cv you do not need to convert to RGB format. But if you want to read CV and show in Matplotlib , Pillow then you have to convert to RGB