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 :)
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