在C#中使用MODI进行OCR.需要从内存而非磁盘读取图像 [英] Using MODI to OCR in C#. Need to read images from memory, not disk

查看:363
本文介绍了在C#中使用MODI进行OCR.需要从内存而非磁盘读取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MODI在内存中已经存在的位图上执行OCR.我似乎找不到解决方案,因为我发现所有示例都使用create方法从磁盘上抓取图像并将其准备用于OCR.但是,我已经将图像保存在内存中并可以读写往返磁盘会消耗太多时间.

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;

推荐答案

您不能.只有一个版本的Create,它需要一个文件. 制作一个临时文件.将图像保存到其中.删除临时文件. 使用Path.GetTempFileName()可以做到这一点.

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);
}

这篇关于在C#中使用MODI进行OCR.需要从内存而非磁盘读取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆