Image Processing — Color Space Conversion : Part 2

Kavini Welarathne
2 min readJul 5, 2022

--

BGR ↔ Gray, BGR ↔ HSV

In this article, I’m going to take you on an adventure with colors.

Today, I wanted to share about

(1). Most widely used Color-space conversion — BGR ↔ Gray, BGR ↔ HSV

(2). Object Tracking

Color-space conversion

The OpenCV offers more than 150 color-space conversion methods. In this article, we will examine the most widely used ones BGR ↔ Gray, BGR ↔ HSV.

BGR ↔ Gray, BGR ↔ HSV.

Color conversion is performed using the cv2.cvtColor(input_image, flag) function

And flag determines the type of conversion.

For conversion, we use the following flags :

  1. BGR → Gray :cv2.COLOR_BGR2GRAY
  2. BGR → HSV :cv2.COLOR_BGR2HSV

Next, I’ll focus on…

Object Tracking

Here I am going to create an application to extract a colored object in a video.

Here are the steps that you need to take:

Step 1: Take each frame of the video.

Step 2: Convert from BGR to HSV color space.

Step 3: We threshold the HSV image for a range of blue colors.

Step 4: Let’s extract only the blue object.

Let’s see the code now:

Option 1 :

Option 2:

Note: Here I’ve attached a video file for your convenience.

So that’s it for now.

Next article is about: Histograms.

Give claps if you liked this article as it would encourage me to write more and will make me happy.

Thank you guys see you soon! ❤️ ✌

--

--

Kavini Welarathne
Kavini Welarathne

Written by Kavini Welarathne

Software Engineer | Researcher |

No responses yet