"OCR running error" when using MODI 2003 with C#
Asked Answered
P

4

6

I've been struggling to get MODI to work properly at all today. Here's the code I'm attempting to use (adapted from the VB given at the Wikipedia entry for MODI.

private void button1_Click( object sender, EventArgs e )
{
    string inputFile = @"C:\testImage.bmp";
    textBox1.Text = GetTextFromImage( inputFile );
}

private string GetTextFromImage( string fileName )
{
    string output = "";
    var doc1 = new MODI.Document();
    doc1.Create( fileName );
    doc1.OCR( MiLANGUAGES.miLANG_ENGLISH, false, false );

    for ( int i = 0; i < doc1.Images.Count; i++ )
    {
        output += doc1.Images[i].Layout.Text;
    }

    doc1.Close();
    return output;
}

When I execute this, I get an error on the OCR() line saying the following:

System.Runtime.InteropServices.COMException was unhandledMessage=OCR running error Source="" ErrorCode=-959967087

Now, I looked up that error code and found another stackoverflow question in which they found that they couldn't run the OCR on small images, but the one in question is 1700x2338, which should be plenty large enough for the cause.

Does anyone have any advice on where to go next with this?

Popinjay answered 14/7, 2011 at 20:49 Comment(0)
B
4

It appears that the MODI failures may be cumulative; however through varying investigation it looks as though it may be tied to the DPI. Modifying the PixelFormat, clearing the background, adjusting the raw image size, and adjusting the OCROrientImage and OCRStraightenImage flags had no effect.

What worked for me was modifying the DPI of the written Bitmap for both horizontal and vertical to 300. The default for a Bitmap is 96 and in working with a specific image that did work I noted the DPI was set at 300.

Brody answered 19/12, 2011 at 22:20 Comment(0)
K
0

I had similar problems and the terribly unhelpful error message seems to be generated when MODI is unable to OCR the bitmap. The solution I came up with is:

1 - Create your bitmap in either of these two formats System.Drawing.Imaging.PixelFormat.Format24bppRgb or System.Drawing.Imaging.PixelFormat.Format16bppRgb555

2 - Clear the background of the bitmap to white and then copy your text "picture" to the middle of it and then do the MODI.Document.Create (......

Karlkarla answered 20/7, 2011 at 15:36 Comment(0)
G
0

Its not a problem on code. Just update office 2003 service pack 3. Here is the link https://www.microsoft.com/en-us/download/details.aspx?id=8

It will work fine....

Ganny answered 14/2, 2017 at 5:52 Comment(1)
Instead of posting links as answer add some text to explanation how this answer help to OP in fixing current issue.ThanksAntilogism
W
-2

Change your code to this:

doc1.OCR;

And let the engine decide its own language.

Whew answered 3/6, 2012 at 4:7 Comment(1)
this causes bad language error when you have charachters with smaller fontsize than 10..Strobel

© 2022 - 2024 — McMap. All rights reserved.