将MODI 2003与C#一起使用时出现"OCR运行错误"

Xan*_*iff 6 c# ocr modi bitmap

我一直在努力让MODI在今天正常工作.这是我试图使用的代码(改编自维基百科MODI条目中给出的VB .

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;
}
Run Code Online (Sandbox Code Playgroud)

当我执行此操作时,我在OCR()行上出现错误,说明以下内容:

System.Runtime.InteropServices.COMException was unhandledMessage=OCR running error Source="" ErrorCode=-959967087
Run Code Online (Sandbox Code Playgroud)

现在,我查找了该错误代码,发现了另一个stackoverflow 问题,他们发现他们无法在小图像上运行OCR,但问题是1700x 2338,这应该足够大到原因.

有没有人对下一步该怎么办?

小智 0

我遇到了类似的问题,当 MODI 无法 OCR 位图时,似乎会生成非常无用的错误消息。我想出的解决方案是:

1 - 使用这两种格式 System.Drawing.Imaging.PixelFormat.Format24bppRgb 或 System.Drawing.Imaging.PixelFormat.Format16bppRgb555 创建位图

2 - 将位图背景清除为白色,然后将文本“图片”复制到其中,然后执行 MODI.Document.Create (......