如何在不使用MODI和OCR的情况下从图像中读取和写入文本 [英] How to read and write text from an image without using MODI and OCR

查看:72
本文介绍了如何在不使用MODI和OCR的情况下从图像中读取和写入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我已经完成了一个代码,用于从图像中提取文本并使用MODI和OCR在文本文件中写入。但问题是,我需要通过添加MDIVWCTL.DLL来安装microsoft office 2007。我不想使用OCR和MO​​DI。 请帮我直接从特定图像中提取文本行而不使用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);
}
}
}
}

推荐答案

无法以某种形式使用OCR从图像中提取文本 作为文本 :OCR查看图像的像素,并确定哪些是字母的一部分然后计算出哪些字母,最后是单词。如果没有某种形式的OCR,你所拥有的只是个别像素而没有文字含义。
You cannot extract text as text from an image without using OCR in some form: OCR looks at the pixels of the image, and determines which ones are parts of letters then works out which letters, and finally words. Without some form of OCR all you have is individual pixels with no textual meaning at all.


这篇关于如何在不使用MODI和OCR的情况下从图像中读取和写入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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