# How to use HSV values for drawing functions in Python?

For example:

cv2.rectangle(img,pt1,pt2, X ,-1)


X = (B,G,R) for red, green, and blue.

I want to draw a square that has a specific (h,s,v) value. Can someone please tell me of a way I can use my (h,s,v) value in a drawing functions such as cv2.rectangle?

I'd rather not use some kind of online converter or anything outside my code please.

edit retag close merge delete

Sorry but I do not quite understand your question. A couple questions 1: Do you already have the BGR to HSV conversion done? 2: What exactly do you mean by draw a square that has a specific (h,s,v) value? Are you trying to do this on the image that was converted from BGR2HSV or an entirely new image which is represented in HSV?

( 2018-02-13 22:09:05 -0500 )edit
1. I've used frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV), but then the frame shows everything in very unrealistic colors.

2. I want to use the drawing function in this format: (cv2.rectangle( img,pt1,pt2,(hue,saturation,value),-1)

3.I want to use cv2.rectangle( img,pt1,pt2,(hue,saturation,value),-1) on a frame that looks like a normal natural frame.

( 2018-02-13 22:22:59 -0500 )edit

Also, using color of (0,255,0) gives me a green rectangle on both my normal frames and hsv frames.

( 2018-02-13 22:31:25 -0500 )edit

Sort by ยป oldest newest most voted

What you need to do is convert the BGR colour to it's respective HSV component. It is a simple calculation that can be a little fun challenge for you to implement. Details of the algorithm can be found here.

If you feel lazy; which I hope you don't, here's a Github repo with the implementation.

Happy Coding!

Cheers :)

more

Official site

GitHub

Wiki

Documentation