我正在尝试使用Modi来对我已经在内存中拥有的位图进行prove。我似乎找不到解决方案,因为我找到的所有示例都使用创建方法从磁盘中获取图像并为OCR准备它。从磁盘上及以外的时间会消耗太多时间。

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;
有帮助吗?

解决方案

你不能。创建只有一个版本,它需要一个文件。制作一个临时文件。将图像保存到其中。删除临时文件。使用path.getTempfileName()做到这一点。

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

其他提示

这个modi.document类可以从流中读取吗?像

Image.FromStream(YourStream);

这样,您可以创建一个内存流并从中读取。

您可以检查Wikipedia的Modi / OCR信息

en.wikipedia.org/wiki/microsoft_office_document_imaging

en.wikipedia.org/wiki/list_of_optical_character_recognition_software

最简单的代码使用Microsoft Office的成像功能(要求MS-Office 2007或更高版本,必须安装成像组件,并且必须将MODI添加到引用中)。

private string OCR ( string fileToOCR)

{

MODI.Document md = new MODI.Document();

md.Create(fileToOCR);

md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);

MODI.Image img = (MODI.Image) md.Images[0];

MODI.Layout layout = img.Layout;

layout = img.Layout;

string result = layout.Text;

md.Close (false);


return result; 

}

通话函数可以是:

private void button6_Click(object sender, EventArgs e)

{

MessageBox.Show ( OCR ("C:\\temp\\in.tif")); 

} 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top