Ask Your Question
1

cv2.COLOR_RGB2HSV is not giving correct HSV values

asked 2018-11-17 17:40:50 -0600

JohneyWood gravatar image

updated 2018-11-19 23:58:27 -0600

Hi, I ran a very simple code as below to convert RGB to HSV, but opencv is giving me incorrect answers. I want to convert yellow from RGB [255,255,0] to HSV, which should give me a value of [60,100,100] or [60,255,255]. However, it is giving me [30,255,255]. Later I tried to use cv2.COLOR_BRG2HSV, it is giving me [90,255,255]. None of these is the correct answer, why?? I'm using macOS Mojave (10.14), Anaconda 1.9.2, python 3.6.4, opencv 3.4.1.

Code:

import numpy as np

import cv2

a = [255,255,0]

HSV_convert = cv2.cvtColor(np.uint8([[a]]), cv2.COLOR_BGR2HSV)

print(HSV_convert)

edit retag flag offensive close merge delete

Comments

i removed your (useless here) screenshots.

berak gravatar imageberak ( 2018-11-17 20:44:37 -0600 )edit
sturkmen gravatar imagesturkmen ( 2018-11-18 00:53:19 -0600 )edit

very helpful, thank you

JohneyWood gravatar imageJohneyWood ( 2018-11-19 16:55:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-11-18 01:30:51 -0600

berak gravatar image

since it has to fit into a uchar Mat / numpy array, Hue values are in the range [0..180], not [0..360], as you expected.

edit flag offensive delete link more

Comments

Thanks, I got it now. So I should be expecting 60/2 = 30, which is the value that opencv gives me.

JohneyWood gravatar imageJohneyWood ( 2018-11-19 16:55:09 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-17 17:39:23 -0600

Seen: 2,898 times

Last updated: Nov 18 '18