We iterate through all the words that ABCocr has found. We then
draw a rectangle round each word in the image and draw our
extracted text in a different color. Finally we save the image.
[C#]
using (Graphics graphics = Graphics.FromImage(bitmap)) {
graphics.PageUnit = GraphicsUnit.Pixel;
foreach (Word word in ocr.Page.Words) {
Font font = new
System.Drawing.Font("Arial", word.Bounds.Height, FontStyle.Regular,
GraphicsUnit.Pixel);
TextFormatFlags flags =
TextFormatFlags.NoClipping | TextFormatFlags.NoPadding;
TextRenderer.DrawText(graphics, word.Text,
font, word.Bounds, Color.Red, flags);
graphics.DrawRectangle(Pens.Green,
word.Bounds);
}
}
bitmap.Save(outPath);
[Visual Basic]
Using gr As Graphics = Graphics.FromImage(bm)
gr.PageUnit = GraphicsUnit.Pixel
For Each word As Word In ocr.Page.Words
Dim flags As TextFormatFlags =
TextFormatFlags.NoClipping Or TextFormatFlags.NoPadding
TextRenderer.DrawText(gr, word.Text, font,
word.Bounds, Color.Red, flags)
gr.DrawRectangle(Pens.Green,
word.Bounds)
Next
End Using
bm.Save(outPath)
|
|
|