Ask Your Question
0

How to use HSV values for drawing functions in Python?

asked 2018-02-13 21:54:59 -0500

masterenol gravatar image

updated 2018-02-13 21:57:57 -0500

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 flag offensive close merge delete

Comments

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?

eshirima gravatar imageeshirima ( 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.

masterenol gravatar imagemasterenol ( 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.

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

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-02-13 22:42:33 -0500

Maybe reading this would help you understand the results you get after the HSV conversion.

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 :)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-02-13 21:54:59 -0500

Seen: 209 times

Last updated: Feb 13 '18