Python OpenCV Example | Convert a Color Image to HSV

In this python opencv example, we will convert a color image to hsv, you can do by following our steps.

It is very easy to convert a color image to hsv in python opencv. Look at example code:

import cv2
img = cv2.imread("bird.jpg")
hsv_image = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
cv2.imshow("HSV Image",hsv_image)
cv2.waitKey(0)

Run this code, you will convert bird.jpg to HSV.

In this example, we use cv2.cvtColor() to convert. Meanwhile, we also can use this function to convert a color image to gray. Here is an example:

Python OpenCV Example | Convert a Color Image to Gray

A HSV image looks like below:

Python OpenCV Example | Convert a Color Image to HSV