2013-08-29 132 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

我已經解決了這個問題,下面設置 轉到項目屬性 變化上 - >內置標籤 - 爲您解答>更改平臺目標

相關問題