Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, February 17, 2011 8:36:54 PM(UTC)
tiger727

Groups: Registered
Posts: 1


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
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Sunday, February 20, 2011 4:42:31 AM(UTC)

Adnan Ismail  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

The following forum post contains a simplified v16.5 .NET OCR demo. Please try it and if it doesn't work, tell me what errors you are getting when you try it.
http://support.leadtools.com/SupportPortal/CS/forums/24675/ShowPost.aspx

The same demo can be used with LEADTOOLS v17 .NET assemblies.
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.082 seconds.