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 ...