2013-08-29 261 views
0

我计划在我的项目中使用OCR并搜索更多OCR方法,但我没有找到任何正确的方法。最后我听说了MODI,我试了一下。当在C#中使用Microsoft Office 2013时出现MODI OCR错误

Retrieving the COM class factory for component with CLSID {40942A6C-1520-4132-BDF8-BDC1F71F547B} failed due to the following error: 80040154

我使用Microsoft Office 2013visual studio 2012:但它抛出下面的错误。

我使用的代码如下:

private void button1_Click(object sender, EventArgs e) 
    { 
     CheckFileType(@"E:\\"); 
    } 

    public void CheckFileType(string directoryPath) 
    { 
     IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator(); 
     while (files.MoveNext()) 
     { 
     //get file extension 
     string fileExtension = Path.GetExtension(Convert.ToString(files.Current)); 

     //get file name without extenstion 
     string fileName=Convert.ToString(files.Current).Replace(fileExtension,string.Empty); 

     //Check for JPG File Format 
     if (fileExtension == ".jpg" || fileExtension == ".JPG") // or // ImageFormat.Jpeg.ToString() 
     { 
     try 
     { 
     //OCR Operations ... 
     MODI.Document md = new MODI.Document(); 
     md.Create(Convert.ToString(files.Current)); 
     md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true); 
     MODI.Image image = (MODI.Image)md.Images[0]; 
     //create text file with the same Image file name 
     FileStream createFile = new FileStream(fileName + ".txt",FileMode.CreateNew); 

     //save the image text in the text file 
     StreamWriter writeFile = new StreamWriter(createFile); 
     writeFile.Write(image.Layout.Text); 
     writeFile.Close(); 
     } 
     catch (Exception) 
     { 
     MessageBox.Show("This Image hasn't a text or has a problem", 
     "OCR Notifications", 
     MessageBoxButtons.OK, MessageBoxIcon.Information); 
     } 
     } 
     } 
    } 

谁能帮我在这?是基于Microsoft Office版本的问题还是我需要进行任何更改?这是更好的OCR DLL吗? 谢谢..

回答

0

我相信要使用MODI,图像必须是.tiff格式或Microsoft专有的.modi格式。根据你的代码,它看起来像你试图转换JPG。

查看此链接以查看VB.NET中用于将TIFF转换为JPEG的示例,反之亦然。

http://code.msdn.microsoft.com/windowsdesktop/VBTiffImageConverter-f8fdfd7f

+0

感谢,但这个问题取决于我的视觉工作室和操作系统的版本。它在Visual Studio 2008中工作得很好,但在vs2012中我们必须做出一些改变 – yasmuru

+0

嗨xpertgun,你能写出我想在vs2012中做什么改变吗? 我也有同样的问题。 – m2pathan

0

我已经解决了这个问题,下面设置 转到项目属性 变化上 - >内置标签 - 为您解答>更改平台目标

相关问题