Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2006

Tip: Looking for answers? Try searching our database.

OCR in MODI.Document Class in Office 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jan Timmer - 16 Feb 2004 14:15 GMT
Hello,

I am trying to OCR a .JPG file using the MODI.Document Class in Office 2003.
This is what I do:

private void Start_OCR(object sender, System.EventArgs e)
{
   MODI.DocumentClass ModiObject = new MODI.DocumentClass();
   MODI.MiLANGUAGES milan = new MiLANGUAGES();
  milan = (MODI.MiLANGUAGES) 9;
  ModiObject.Create(@"C:\TEST\MYDOC.JPG");

  ModiObject.OCR(milan, true,true);

This results in an 'OCR running error'.

The problem is that I can hardly find any documentation about this stuff.
Not in MSDN, nor on the MSDN website. Is there anybody who has got
this stuff running?

TIA,

Jan
Kjetil Klaussen - 30 Apr 2004 15:26 GMT
This is true! Documentation around the use of the MODI object is more or less non-existent... But there is hope :

This is how I made it work

string tifFile = "myPicture.tif", recString = ""
MODI.Document tifDoc = new Document()
tifDoc.Create(tifFile)
tifDoc.OCR(MiLANGUAGES.miLANG_ENGLISH, false, false)
tifDoc.Save()
MODI.Image tifImg = (MODI.Image)tifDoc.Images[0]
recString = "Result from Office MODI Ocr: " + tifImg.Layout.Text
tifDoc.Close(true)

The only problem I'm having is that the document.create() method doesn't have any overloads. I would really like to send in a stream instead of the filepath, because it seems impossible to get the object to release the file when the close() method is called. Or maybe the problem is that the close() method doesn't work properly? I don't know. But I haven't found any ways to unlock the file when I'm done yet... If you find a way to do it, please let me know :)
Scott R. Grabowski - 06 Jun 2004 22:15 GMT
I've found a solution to the file not getting released after calling the close() method.  I had to force garbage collection.  See below:

private string GetOCRText(string strFilename)
{
   string strRetVal = "";
   MODI.Document miDoc = new MODI.Document();
   MODI.Image miImage;
   int nWordCount = -1;

   // Open the file
   miDoc.Create(strFilename);
   miImage = (MODI.Image)miDoc.Images[0];

   // Determine if this image has saved OCR information
   try
   {
       nWordCount = miImage.Layout.NumWords;
   }
   catch
   {
       nWordCount = -1;
   }

   // If image wasn't OCR'd yet, do it now and save the results
   if (nWordCount == -1)
   {
       miImage.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
       miDoc.Save();
   }

   // Get the OCR'd text
   strRetVal = miImage.Layout.Text;

   // Cleanup
   miDoc.Close(false);
   miImage = null;
   miDoc = null;

   // Force garbage collection so image file is closed properly
   GC.Collect();
   GC.WaitForPendingFinalizers();

   return strRetVal;
}

I hope that this is helpful to someone...

-Scott
---
Scott R. Grabowski
sg2j@core.com

> This is true! Documentation around the use of the MODI object is more or less non-existent... But there is hope :)
>
[quoted text clipped - 10 lines]
>
> The only problem I'm having is that the document.create() method doesn't have any overloads. I would really like to send in a stream instead of the filepath, because it seems impossible to get the object to release the file when the close() method is called. Or maybe the problem is that the close() method doesn't work properly? I don't know. But I haven't found any ways to unlock the file when I'm done yet... If you find a way to do it, please let me know :)
Scott R. Grabowski - 06 Jun 2004 22:23 GMT
I've found a solution to the file not releasing after calling the close() method.  I had to force garbage collection.  See below:

   private string GetOCRText(string strFilename)
   {
       string strRetVal = "";
       MODI.Document miDoc = new MODI.Document();
       MODI.Image miImage;
       int nWordCount = -1;

       // Open the file
       miDoc.Create(strFilename);
       miImage = (MODI.Image)miDoc.Images[0];

       // Determine if this image has saved OCR information
       try
       {
           nWordCount = miImage.Layout.NumWords;
       }
       catch
       {
           nWordCount = -1;
       }

       // If image wasn't OCR'd yet, do it now and save the results
       if (nWordCount == -1)
       {
           miImage.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
           miDoc.Save();
       }

       // Get the OCR'd text
       strRetVal = miImage.Layout.Text;

       // Cleanup
       miDoc.Close(false);
       miImage = null;
       miDoc = null;

       // Force garbage collection so image file is closed properly
       GC.Collect();
       GC.WaitForPendingFinalizers();

       return strRetVal;
   }

I hope that this is helpful to someone...

-Scott
---
Scott R. Grabowski
sg2j@core.com

> This is true! Documentation around the use of the MODI object is more or less non-existent... But there is hope :)
>
[quoted text clipped - 10 lines]
>
> The only problem I'm having is that the document.create() method doesn't have any overloads. I would really like to send in a stream instead of the filepath, because it seems impossible to get the object to release the file when the close() method is called. Or maybe the problem is that the close() method doesn't work properly? I don't know. But I haven't found any ways to unlock the file when I'm done yet... If you find a way to do it, please let me know :)
lameneural - 21 Sep 2006 06:47 GMT
Hi Jan

Do you happen to find a solution to your error? I am having the same problem.
The call on OCR method just goes fine in VB, but when compiled, I am having
the same error:

Runtime error '-959967087 (c6c81091)':
OCR running error

Any light shed is greatly appreciated. BTW, my program is made in VB6. :)

Regards;
erik

>Hello,
>
[quoted text clipped - 19 lines]
>
>Jan

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.