In this example, we will learn how to convert an RGB format Image in an HSV format Image using OpenCV in Python. An HSV is another type of color space in which H stands for Hue, S stands for Saturation and V stands for Value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # open-cv library is installed as cv2 in python # import cv2 library into this program import cv2 # read an image using imread() function of cv2 # we have to pass only the path of the image img = cv2.imread(r'C:/Users/user/Desktop/pic1.jpg') # displaying the image using imshow() function of cv2 # In this : 1st argument is name of the frame # 2nd argument is the image matrix cv2.imshow('original image',img) # converting the colourfull image into HSV format image # using cv2.COLOR_BGR2HSV argument of # the cvtColor() function of cv2 # in this : # ist argument is the image matrix # 2nd argument is the attribute HSV_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV) # displaying the Hsv format image cv2.imshow('HSV format image',HSV_img) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.