First time I found helpfull to push this to git
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using Tesseract;
|
||||
|
||||
namespace OCR_tester
|
||||
{
|
||||
public class MainZone : Zone
|
||||
{
|
||||
List<Rectangle> detectedText;
|
||||
public MainZone(Image fullImage, Rectangle bounds) : base(fullImage, bounds)
|
||||
{
|
||||
AutoCalibrate();
|
||||
}
|
||||
public void AutoCalibrate()
|
||||
{
|
||||
detectedText = new List<Rectangle>();
|
||||
TesseractEngine engine = new TesseractEngine(Window.tessDataFolder.FullName, "eng", EngineMode.Default);
|
||||
var tessImage = Pix.LoadFromMemory(Window.ImageToByte(ZoneImage));
|
||||
|
||||
Page page = engine.Process(tessImage);
|
||||
using (var iter = page.GetIterator())
|
||||
{
|
||||
iter.Begin();
|
||||
do
|
||||
{
|
||||
Rect boundingBox;
|
||||
if (iter.TryGetBoundingBox(PageIteratorLevel.Word, out boundingBox))
|
||||
{
|
||||
detectedText.Add(new Rectangle(boundingBox.X1, boundingBox.Y1, boundingBox.Width, boundingBox.Height));
|
||||
}
|
||||
//var text = iter.GetText(PageIteratorLevel.Word);
|
||||
} while (iter.Next(PageIteratorLevel.Word));
|
||||
}
|
||||
|
||||
//Now that we have all the detected text we can try to split the zone
|
||||
|
||||
foreach (Rectangle rect in detectedText)
|
||||
{
|
||||
//To do
|
||||
}
|
||||
}
|
||||
public Bitmap Draw()
|
||||
{
|
||||
Bitmap image = ZoneImage;
|
||||
Graphics g = Graphics.FromImage(image);
|
||||
|
||||
foreach (Rectangle rect in detectedText)
|
||||
{
|
||||
g.DrawRectangle(Pens.Red,rect);
|
||||
}
|
||||
image.Save(@"C:\Users\Moi\Desktop\imgDump\test.png");
|
||||
return image;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user