[Python] OpenCV RGB2HSV color space convertion gives wrong results, colors aren't similar

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    Why the color space conversion goes wrong (images are not roughly similar) when I use OpenCV COLOR_RGB2HSV and goes right when using image.convert('HSV') ? What I'm doing wrong?

    import cv2
    from PIL import Image

    image = Image.open('picture_1.jpg')

    img1=cv2.imread('picture_1.jpg')
    img2=cv2.cvtColor(img1,cv2.COLOR_BGR2RGB)
    img3=cv2.cvtColor(img2,cv2.COLOR_RGB2HSV)
    img4=cv2.cvtColor(img3,cv2.COLOR_HSV2RGB)

    fig, ax = plt.subplots(2, 2, figsize=(16, 6), subplot_kw=dict(xticks=[], yticks=[]))
    fig.subplots_adjust(wspace=0.05)
    ax[0][0].imshow(img1)
    ax[0][0].set_title('BGR', size=16)
    ax[0][1].imshow(img2)
    ax[0][1].set_title('RGB', size=16);
    ax[1][0].imshow(img3)
    ax[1][0].set_title('HSV', size=16);
    ax[1][1].imshow(image.convert('HSV'))
    ax[1][1].set_title('HSV', size=16);


    I got this results:

    [​IMG]

    Continue reading...

Compartilhe esta Página