使用MODI时出现OCR错误 - Sharepoint 2007

时间:2015-07-02 15:46:22

标签: c# ocr modi

我的机器安装了Office 2010 我为OCR下载了Sharepoint 2007 MODI。 我正在使用VS2012。

我收到以下错误消息:

  

ImageOCR_Modi.exe中出现未处理的“System.Runtime.InteropServices.COMException”类型异常

以下是截图:

enter image description here

我开始了解Office 2010删除了MODI功能,因此没有来自MS的支持。因此无法与Office 2010一起使用

代码:

public string CheckFileAndDoOCR(string directoryPath)
{
    string TheTxt = "";
    IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();

    while (files.MoveNext())
    {
        // FileInfo
        FileInfo sudhir = new FileInfo(Convert.ToString(files.Current));

        // Check for JPG File Format
        if (sudhir.Extension == ".jpg" || foo.Extension == ".JPG")
        // or // ImageFormat.Jpeg.ToString()
        {
            // Start OCR Procedure
            TheTxt = DoOCRExact(sudhir.FullName);
            // Create TXT file next to ImageFile
            string txtFileName = sudhir.DirectoryName + "\\" + sudhir.Name.Replace(sudhir.Extension, "") + ".txt";
            FileStream createFile = new FileStream(txtFileName, FileMode.OpenOrCreate);
            // Save the text in to TXT file
            StreamWriter writeFile = new StreamWriter(createFile);
            writeFile.Write(TheTxt);
            // Close
            writeFile.Close();
            createFile.Close();
        }

        try
        { foo.Delete(); }
        catch (Exception ex)
        {

        }
    }
    return TheTxt;
}

public string DoOCRExact(string FullPath)
{
    string txt;

    // OCR Operations...
    MODI.Document md = new MODI.Document(); // Create MODI.Document
    md.Create(FullPath); // Fill MODI.Document with my file
    md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); // OCR();
    // Image from file
    MODI.Image image = (MODI.Image)md.Images[0];
    txt = image.Layout.Text;
    MODI.Word word = image.Layout.Words[0];
    // Close OCR
    word = null;
    image = null;
    md.Close(false);
    md = null;

    // Finalize
    GC.Collect();
    GC.WaitForPendingFinalizers();

    // Return Text
    return txt;
}

0 个答案:

没有答案