Using MODI to OCR in C#. Need to read images from memory, not disk

Amit picture Amit · Nov 2, 2010 · Viewed 10.9k times · Source

I'm trying to use MODI to perfom OCR on bitmaps I already have in memory. I can't seem to find a solution to this as all the examples I find use the create method to grab the image from the disk and prepares it for the OCR., however, I already have the image on memory and writing and reading i to and from the disk consumes too much time.

Bitmap bmp = ...
//Instantiate the MODI.Document object
MODI.Document md = new MODI.Document();
//The Create method grabs the picture from disk snd prepares for OCR.          
md.Create("C:\\bmp.gif"); //but I don't want to read from disk :(
//Do the OCR.
md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
//Get the first (and only image)
MODI.Image image = (MODI.Image)md.Images[0];
//Get the layout.
MODI.Layout layout = image.Layout;

Answer

plinth picture plinth · Nov 2, 2010

You can't. There is only one version of Create and it takes a file. Make a temp file. Save the image into it. Delete the temp file. Use Path.GetTempFileName() to do that.

string file = Path.GetTempFileName();
try {
    SaveImageToFile(image, file); // you decide how to best do this
    md.Create(file);
    // etc.
}
finally {
    File.Delete(file);
}