O'Reilly logo

Learn OpenCV 4 by Building Projects - Second Edition by Prateek Joshi, Vinicius G. Mendonca, David Millan Escriva

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating connected areas

If you take a closer look at the image, you'll notice that the letters are always together in blocks, formed by text paragraphs. That leaves us with the question, how do we detect and remove these blocks?

The first step is to make these blocks even more evident. We can do this by using the dilation morphological operator. Recall from Chapter 8, Video Surveillance, Background Modeling, and Morphological Operations, that dilation makes the image elements thicker. Let's look at a small code snippet that does the trick:

auto kernel = getStructuringElement(MORPH_CROSS, Size(3,3)); 
Mat dilated; 
dilate(input, dilated, kernel, cv::Point(-1, -1), 5); 
imshow("Dilated", dilated); 

In the preceding code, we start by creating ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required