Converting images from RGB to HSV

Here is a code snippet we can use for converting an image from RGB colour space to HSV colour space. OpenCV uses BGR format instead of RGB. Therefore, we have to use the CV_BGR2HSV flag to convert the image to HSV space and then the “split” method to separate the hue, saturation and value channels.