.NET OCRing an Image

后端 未结 7 655
挽巷
挽巷 2021-02-06 05:56

I\'m trying to use MODI to OCR a window\'s program. It works fine for screenshots I grab programmatically using win32 interop like this:

public string SaveScreen         


        
相关标签:
7条回答
  • 2021-02-06 06:06

    I had the same issue while using the

    doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
    

    on a tiff file that was 2400x2496. Resizing it to 50%(reducing the size) fixed the problem and the method was not throwing the exception anymore, however, it was incorrectly recognizing the text like detecting "relerence" instead of "reference" or "712017" instead of "712517". I kept trying different image sizes but they all had the same issue, until i changed the command to

    doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
    

    which meant that i don't want it to detect the orientation and not to fix any skewing. Now the command works fine on all images including the 2400x2496 tiff.

    Hope this helps out people facing the same problem

    0 讨论(0)
  • 2021-02-06 06:09

    the modi ocr is working only tif with me. try to save image in "tif".

    sorry my bad english

    0 讨论(0)
  • 2021-02-06 06:14

    Looks as though the answer is in giving MODI a bigger canvas. I was also trying to take a screenshot of a control and OCR it and ran into the same problem. In the end I took the image of the control, copied the image into a larger bitmap and OCRed the larger bitmap.

    Another issue I found was that you must have a proper extension for your image file. In other words, .tmp doesn't cut it.

    I kept the work of creating a larger source inside my OCR method, which looks something like this (I deal directly with Image objects):

    public static string ExtractText(this Image image)
    {
        var tmpFile = Path.GetTempFileName();
        string text;
        try
        {
            var bmp = new Bitmap(Math.Max(image.Width, 1024), Math.Max(image.Height, 768));
            var gfxResize = Graphics.FromImage(bmp);
            gfxResize.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height));
            bmp.Save(tmpFile + ".bmp", ImageFormat.Bmp);
            var doc = new MODI.Document();
            doc.Create(tmpFile + ".bmp");
            doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
            var img = (MODI.Image)doc.Images[0];
            var layout = img.Layout;
            text = layout.Text;
        }
        finally
        {
            File.Delete(tmpFile);
            File.Delete(tmpFile + ".bmp");
        }
    
        return text;
    }
    

    I'm not sure exactly what the minimum size is, but it appears as though 1024 x 768 does the trick.

    0 讨论(0)
  • 2021-02-06 06:18

    what solved my situation was using a photo editor (Paint.NET) and use the sharpen effect at maximum.

    I also used: doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);

    0 讨论(0)
  • 2021-02-06 06:24
    doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
    

    Which means that I don't want it to detect the orientation and not fix any skewing. Now the command works fine on all images including the 2400x2496 tiff.

    But image should be in .tif.

    Hope this helps out people facing the same problem.

    0 讨论(0)
  • 2021-02-06 06:26

    I had the same problem "OCR running problem" with some images. I re-scaled the image (in my case by 50%), i.e. reduced its size and voila! it works!

    0 讨论(0)
提交回复
热议问题