1

I aim to detect all the on per line basis. I saw many solutions using contouring the image and then generating the highlights, but I want it per line. Like for this image below

original

I want this as the output out

Whereas using those methods, this is the output enter image description here

Tavish Jain
  • 155
  • 1
  • 2
  • 13
  • You should post some code as a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). You might consider doing an [erosion](https://docs.opencv.org/master/d9/d61/tutorial_py_morphological_ops.html) with a kernel that will operate heavily in the x direction. `kernel = np.ones((2,20), np.uint8) will work on your image as posted with 8 iterations. This will make all of the text on one line join together. Then do a dilate with 8 iterations. Then find contours. – bfris Jul 29 '20 at 16:32

1 Answers1

2

Not a fully worked answer, but hopefully enough to get you started. Look at the following diagram:

enter image description here

You can use Numpy's np.sum(... axis=1) or np.mean(... axis=1) to sum the pixels across the rows of your image. You can now find the spaces between your lines of text by looking for runs of white in the column of row-totals.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Ohhhh, this is a good idea actually. It could actually work out. Thank you soo much. I'll just check this out. But one thing that bothers me is that an image could also have not noise, and not as such clear white color in the background, how would you handle that noise ? By setting some threshold sum value ? – Tavish Jain Jul 30 '20 at 15:36