A simple segmentation algorithm can help you out. Heres how the algorithm works:
- scan pixels from left to right and
record the position of the first
black (whatever the color of your
line is) pixel.
- carry on this process
unless you find one whole scan when
you don't find the black pixel.
Record this position as well.
- We are
just interested in the Y positions
here. Now using this Y position
segment the image horizontally.
- Now
we are going to do the same process
but this time we are going to scan
from top to bottom (one column at a
time) in the segment we just created.
- This time we are interested in X
positions.
- So in the end we get every
lines extents or you can say a
bounding box for every line.
- The
total count of these bounding boxes
is the number of lines.
You can do many optimizations in the algorithm according to your needs.