Hi, I am just trying to integrate Leadtools OCR engine to my project. I get a piece of code from CodeProject tells me how to integrate OCR engine to .net projects.
But somehow it doesn't work. I try the same process from the demo program, it read me the number which I need. But when I try to process it with my application. It returns me empty string. I dont know why. Below is the code part shows how I process the image in my application with OCR engine. Is that anyone can tell me whats wrong with it?
public string GetTextFromBuffImage(Bitmap image)
{
// *** Step 3: Create an OCR document with one or more pages.
IOcrDocument ocrDocument = _ocrEngine.DocumentManager.CreateDocument();
var rasterImage = RasterImageConverter.ConvertFromImage(image, ConvertFromImageOptions.None);
// Add all the pages of a multi-page TIF image to the document
ocrDocument.Pages.AddPages(rasterImage, 1, -1, null);
// *** Step 4: Establish zones on the page(s), either manually or automatically
// Automatic zoning
LogicalRectangle rect = new LogicalRectangle(0, 0, image.Width, image.Height, LogicalUnit.Pixel);
OcrZone zone = new OcrZone();
zone.Bounds = RestrictZoneBoundsToPage(ocrDocument.Pages[0], rect);
ocrDocument.Pages[0].Zones.Add(zone);
// *** Step 7: (Optional) Set any special recognition module options
// Change the fill method for the first zone in the first page to be default
OcrZone ocrZone = ocrDocument.Pages[0].Zones[0];
ocrZone.FillMethod = OcrZoneFillMethod.Default;
ocrDocument.Pages[0].Zones[0] = ocrZone;
// *** Step 8: Recognize
ocrDocument.Pages.Recognize(null);
// *** Step 9: Save recognition results
// Save the results to a PDF file
var result = ocrDocument.Pages[0].RecognizeText(null);
ocrDocument.Dispose();
return result;
}
private static LogicalRectangle RestrictZoneBoundsToPage(IOcrPage ocrPage, LogicalRectangle bounds)
{
RasterImage image = ocrPage.GetRasterImage();
LeadRect pageBounds = new LeadRect(0, 0, image.ImageWidth, image.ImageHeight);
LeadRect rc = bounds.ToRectangle(ocrPage.DpiX, ocrPage.DpiY);
rc = LeadRect.Intersect(pageBounds, rc);
return LogicalRectangle.FromRectangle(rc);
}
BTW I initialised my engine out side the class passed in as a parameter. Thanks a lot.
Using LeadTools V17