问题描述
我已经完成了一个代码,用于从图像中提取文本并使用MODI和OCR在文本文件中写入。但问题是,我需要通过添加MDIVWCTL.DLL来安装microsoft office 2007。我不想使用OCR和MODI。 请帮我直接从特定图像中提取文本行而不使用OCR方法并将其写入.txt文件。
代码如下:
public static void CheckFileType(string directoryPath)
{
IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
while(files.MoveNext())
{
string fileExtension = Path.GetExtension(Convert.ToString(files.Current));
string fileName =
Convert.ToString(files.Current).Replace(fileExtension,string.Empty);
if(fileExtension ==.jpg|| fileExtension ==.JPG)
{
try
{
MODI.Document md = new MODI.Document();
md.Create(Convert.ToString(files.Current));
md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH,true,true);
MODI.Image image =(MODI.Image)md.Images [0];
//创建具有相同图像文件名的文本文件
FileStream createFile =
新FileStream(fileName +。txt,FileMode.CreateNew) ;
//将图像文本保存在文本文件中
StreamWriter writeFile = new StreamWriter(createFile);
writeFile.Write(image。 Layout.Text);
writeFile.Close();
}
catch(Exception exc)
{
//取消注释下面的代码以查看预期的错误
//MessageBox.Show (exc.Message,
//OCR异常,
//MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
Hi,
I have done a code for extracting the text from an image and writing in a text file using MODI and OCR. But the problem is, i need to install microsoft office 2007 with adding MDIVWCTL.DLL. I dont want to use OCR and MODI. Please help me to extract text lines from a particular image directly without using OCR method and write it into a .txt file.
Code below :
public static void CheckFileType(string directoryPath)
{
IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
while (files.MoveNext())
{
string fileExtension = Path.GetExtension(Convert.ToString(files.Current));
string fileName =
Convert.ToString(files.Current).Replace(fileExtension,string.Empty);
if (fileExtension == ".jpg" || fileExtension == ".JPG")
{
try
{
MODI.Document md = new MODI.Document();
md.Create(Convert.ToString(files.Current));
md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
MODI.Image image = (MODI.Image)md.Images[0];
//create text file with the same Image file name
FileStream createFile =
new FileStream(fileName + ".txt", FileMode.CreateNew);
//save the image text in the text file
StreamWriter writeFile = new StreamWriter(createFile);
writeFile.Write(image.Layout.Text);
writeFile.Close();
}
catch (Exception exc)
{
//uncomment the below code to see the expected errors
//MessageBox.Show(exc.Message,
//"OCR Exception",
//MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
推荐答案
这篇关于如何在不使用MODI和OCR的情况下从图像中读取和写入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!