Tessnet2 image Recognition (2)

Source: Internet
Author: User
Tags tesseract ocr

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.