Character Segmentation using Opencv and Numpy

Nikhil Khandelwal
2 min readJun 6, 2021

In this article, we are going to learn how to extract a character from a word.

We will start with the digitally written character. Here we will use a very simple approach called vertical project profile.

Sample Image

So First we will do thresholding and invert the image. We can set the lower and upper limit for thresholding based on the image.

Inverted Image

Vertical Projection Profile

Vertical projection profile is calculated for every column as the sum of all row pixel values inside the column.

So basically we are calculating the sum of pixels column-wise. wherever the character is not present sum will be zero because of the black background.

We need to get the index position of 0 value and extract the character using these positions. We will take the index value just after the character and just before the character. The same can be visualized in the below image.

With the help of these index position, we can extract each character successfully.

Next, We will modify the above technique for the handwritten characters and see how it works.

--

--