获取图片中的文本--MODI

http://www.aspsnippets.com/Articles/Read-Extract-Text-from-Image-OCR-in-ASPNet-using-C-and-VBNet.aspx

1. 根据上面的链接,做好各种准备工作

2.HTML tag

 <div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button Text="Upload" runat="server" OnClick="Unnamed_Click"/>
<hr />
<asp:Label ID="lblText" runat="server" />
</div>

2. 添加命名空间

using MODI;
using System.IO;

3.上传文件事件

 protected void Unnamed_Click(object sender, EventArgs e)
{
string filePath = Server.MapPath("~/Image/" + Path.GetFileName(FileUpload1.PostedFile.FileName));
FileUpload1.SaveAs(filePath);
string extractText = this.ExtractTextFromImage(filePath);
lblText.Text = extractText.Replace(Environment.NewLine, "<br />");
}

4.从图片文件中获取Text方法

  private string ExtractTextFromImage(string filePath)
{
MODI.Document modiDocument = new MODI.Document();
modiDocument.Create(filePath); modiDocument.OCR(MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED,true,true);
MODI.Image modiImage = (modiDocument.Images[] as MODI.Image);
string extractedText = modiImage.Layout.Text;
modiDocument.Close();
return extractedText;
}
上一篇:Apache配置压缩优化时报错——undefined symbol: inflateEnd


下一篇:PHPDocumentor代码注释规范说明