1. Reference Tessnet2.dll (only NET2.0 version)
2. View Page
<%@ Page Language="C #"MasterPageFile="~/views/shared/site.master"Inherits="System.Web.Mvc.ViewPage" %><asp:contentID= "Content1"ContentPlaceHolderID= "Titlecontent"runat= "Server">Home Page</asp:content><asp:contentID= "Content2"ContentPlaceHolderID= "MainContent"runat= "Server"> <H2><%: viewdata["Message"] %></H2> <P>to learn more about ASP. NET MVC, go to<ahref= "Http://asp.net/mvc"title= "ASP. NET MVC website">Http://asp.net/mvc</a>. </P><formID= "Form1"runat= "Server"enctype= "Multipart/form-data"Action= "Indexnew" > <Div> <aID= "Addattach"href="#">Add upload File</a> <DivID= "Files"> <inputtype= "File"name= "F1"/><%-- <input type="file"name="F2"/>--%> </Div> <inputtype= "Submit"value= "Submit" /> </Div> </form></asp:content>
View Code
3. Background code
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;usingTessnet2;usingSystem.Drawing;usingSystem.Drawing.Imaging;namespacemvcapplicationandtesseert2.controllers{[HandleError] Public classHomecontroller:controller { PublicActionResult Index () {returnView (); } PublicActionResult indexnew () {httppostedfilebase HF= httpcontext.request.files[0]; stringPath = Server.MapPath ("~/image/"+datetime.now.tostring ("YYYYMMDDHHMMSS")+". jpg"); Hf. SaveAs (path); //D:\CSharp\TessnetTest\ReCaptcha.jpg is the path of the image to be identified in the computerBitmap map =NewBitmap (path);//@ "D:\3.png"Tessnet2. Tesseract OCR=NewTessnet2. Tesseract ();//declaring an OCR class stringTXT =""; List<tessnet2. word> result =NewList<tessnet2. Word>(); Try {//Current recognition variable settings: Numbers and uppercase letters, which can result in unrecognized lowercase letters, plus lowercase lettersOcr. SetVariable ("tessedit_char_whitelist","0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); //applies the current language pack. Note that Tessnet2 is supported in multi-lingual. Language pack Download Link:http://code.google.com/p/tesseract-ocr/downloads/list //D:\CSharp\TessnetTesttessdata is the path of the language pack in the computerOcr. Init (Server.MapPath ("~/tessdata"),"Eng",false); Result=OCR. DOOCR (map, Rectangle.empty); foreach(Tessnet2. Word Wordinchresult) {txt+=Word. Text; } Console.WriteLine (TXT); Console.ReadLine (); } Catch(Exception ex) {}returnContent (TXT); } PublicActionResult About () {returnView (); } } }
View Code
Demo
Tessnet2 image Recognition (2)