"OCR Runtime Error" when using MODI 2003 with C #

I'm struggling to get MODI to work fine today. Here's the code I'm trying to use (adapted from the VB specified in 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 do this, I get an error in the OCR () line saying the following:

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

Now I looked through this error code and found another stackoverflow question in which they found that they cannot run OCR on small images, but one of them is 1700 x 2338 , which should be big enough for a reason.

Does anyone have any tips on where to go next?

+6
source share
4 answers

It appears that MODI errors can be cumulative; however, through various studies, it seems that he may be attached to DPI. Changing PixelFormat , cleaning the background, adjusting the size of the raw image, and adjusting the OCROrientImage and OCRStraightenImage did not affect.

For me, the DPI modification of the written Bitmap worked for horizontal and vertical values ​​up to 300. The default value for Bitmap is 96, and when working with a specific image that really worked, I noted that DPI was set to 300.

+4
source

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

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

2 - Clear the background image of the bitmap to white, and then copy the text "picture" in the middle, and then execute MODI.Document.Create (......

0
source

This is not a problem with the 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 ....

0
source

Change the code as follows:

 doc1.OCR; 

And let the engine decide its own language.

-2
source

Source: https://habr.com/ru/post/892791/


All Articles