【问题标题】:Using MODI to OCR in C#. Need to read images from memory, not disk在 C# 中使用 MODI 到 OCR。需要从内存而不是磁盘中读取图像
【发布时间】:2010-11-02 19:22:34
【问题描述】:

我正在尝试使用 MODI 对内存中已有的位图执行 OCR。我似乎找不到解决方案,因为我发现的所有示例都使用 create 方法从磁盘中获取图像并为 OCR 准备它。但是,我已经在内存中保存了图像并写入和读取 i往返磁盘消耗太多时间。

Bitmap bmp = ...
//Instantiate the MODI.Document object
MODI.Document md = new MODI.Document();
//The Create method grabs the picture from disk snd prepares for OCR.          
md.Create("C:\\bmp.gif"); //but I don't want to read from disk :(
//Do the OCR.
md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
//Get the first (and only image)
MODI.Image image = (MODI.Image)md.Images[0];
//Get the layout.
MODI.Layout layout = image.Layout;

【问题讨论】:

  • 老兄,你首先需要一个拼写检查器。
  • 这个问题明显是手写的,然后通过OCR转换。
  • 我应该在提交之前先阅读它。对不起。

标签: c# ms-office ocr modi


【解决方案1】:

你不能。 Create 只有一个版本,它需要一个文件。 制作一个临时文件。将图像保存到其中。删除临时文件。 使用 Path.GetTempFileName() 来做到这一点。

string file = Path.GetTempFileName();
try {
    SaveImageToFile(image, file); // you decide how to best do this
    md.Create(file);
    // etc.
}
finally {
    File.Delete(file);
}

【讨论】:

  • 我知道我可以创建一个 tmp 文件并执行此操作,但这种方式对于我想要完成的任务来说太慢了。我需要重复很多次,所以如果这是唯一对我来说很糟糕的方式,我猜。不过,感谢您的回答。
  • 太糟糕了。您还可以确保在编写临时文件时(并且您将不得不这样做),您使用的文件格式可以快速写入和快速解析。这通常意味着没有压缩的 TIFF 或 BMP 或没有压缩和没有过滤器的 PNG。没有压缩的 BMP 可能会是最快的。
  • 顺便说一句,GIF 不是最适合这个任务吗?
  • 将图像保存到磁盘并让 modi 通常加载图像所需的时间与实际对图像执行 OCR 所需的时间相比通常是微不足道的。
【解决方案2】:

这个 MODI.Document 类可以从流中读取吗?像

Image.FromStream(YourStream);

这样你就可以创建一个内存流并从中读取。

【讨论】:

  • 我不知道。这个 MODI 的东西没有太多的文档。
【解决方案3】:

您可以在维基百科上查看 MODI / OCR 信息

en.wikipedia.org/wiki/Microsoft_Office_Document_Imaging

en.wikipedia.org/wiki/List_of_optical_character_recognition_software

【讨论】:

    【解决方案4】:

    使用 Microsoft Office 的图像处理功能对图像进行 OCR 的最简单代码(需要 MS-Office 2007 或更高版本,必须安装图像处理组件并且必须将 MODI 添加到引用中)。

    private string OCR ( string fileToOCR)
    
    {
    
    MODI.Document md = new MODI.Document();
    
    md.Create(fileToOCR);
    
    md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
    
    MODI.Image img = (MODI.Image) md.Images[0];
    
    MODI.Layout layout = img.Layout;
    
    layout = img.Layout;
    
    string result = layout.Text;
    
    md.Close (false);
    
    
    return result; 
    
    }
    

    调用函数可以是:

    private void button6_Click(object sender, EventArgs e)
    
    {
    
    MessageBox.Show ( OCR ("C:\\temp\\in.tif")); 
    
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 2015-08-06
      • 2015-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      相关资源
      最近更新 更多