I have a Talmud page like these:
And I want to find the text areas with opencv to get such a result, that each text will be on its own like this:
In the attached image, each area is marked in a different color, and text has a number, what is important is to identify the area belonging to each text, and differentiate it from the area belonging to another text, the numerical order does not matter.
Doing it with the eyes is really easy, according to the white stripes that pass between the texts, but I tried to do it with opencv and I could not.
In the following code I try to catch all the letters and turn them into black rectangles, Then magnify each rectangle to meet with a neighboring rectangle, And so the whole area of the text will be black, and between the texts there will be a clear white stripe.
I do not know how to proceed, and if it is a good approach.
public List<Rectangle> getRects(Mat grayImg)
{
BlobCounter blobCounter = new BlobCounter();
blobCounter.ObjectsOrder = ObjectsOrder.None;
blobCounter.ProcessImage(grayImg);
IEnumerable<Blob> blobs = blobCounter.GetObjectsInformation();
var blackBlobs = grayImg.Clone;
foreach (var b in blobs)
blackBlobs.Rectangle(b.Rectangle.ToCvRect, Scalar.Black, -1);
var widths = blobs.Select(X => X.Rectangle.Width).ToList;
widths.Sort();
var median = widths(widths.Count / (double)2);
Mat erodet = new Mat();
Cv2.Erode(grayImg, erodet, null, iterations: median);
using (Window win = new Window())
{
win.ShowImage(erodet);
win.WaitKey();
}
}
Thanks in advance, any help would be appreciated.
Additional clarification:
As you can see in the previous image, the text areas are not rectangular, But these areas can be described as a collection of rectangles of different sizes arranged in a pile, one on top of the other.
Note that when two rectangles belong to the same text, do not arrange one rectangle next to another rectangle, but only one above the other.
What I am trying to achieve is a collection of these rectangles and knowing each rectangle to which text it belongs.
An answer can be in any programming language, especially in C++ Python and C#







