博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tessnet2图片识别(2)
阅读量:6934 次
发布时间:2019-06-27

本文共 2230 字,大约阅读时间需要 7 分钟。

1. 引用 tessnet2.dll (只有NET2.0版本)

2. 视图页

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
主页

<%: ViewData["Message"] %>

若要了解有关 ASP.NET MVC 的更多信息,请访问 http://asp.net/mvc

添加上传文件
<%--
--%>
View Code

3.后台代码

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using tessnet2;using System.Drawing;using System.Drawing.Imaging;namespace MvcApplicationAndTesseert2.Controllers{    [HandleError]    public class HomeController : Controller    {        public ActionResult Index()        {            return View();        }        public ActionResult IndexNew()        {            HttpPostedFileBase hf = HttpContext.Request.Files[0];            string path = Server.MapPath("~/image/"+DateTime.Now.ToString("yyyyMMddHHmmss")+".jpg");            hf.SaveAs(path);            //D:\CSharp\TessnetTest\ReCaptcha.jpg是待识别图片在电脑中的路径            Bitmap map = new Bitmap(path);//@"D:\3.png"            tessnet2.Tesseract ocr = new tessnet2.Tesseract();//声明一个OCR类               string txt = "";            List
result = new List
(); try {
//当前识别变量设置:数字与大写字母,这种写法会导致无法识别小写字母,加上小写字母即可 ocr.SetVariable("tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); //应用当前语言包。注,Tessnet2是支持多国语的。语言包下载链接:http://code.google.com/p/tesseract-ocr/downloads/list //D:\CSharp\TessnetTesttessdata是语言包在电脑中的路径 ocr.Init(Server.MapPath("~/tessdata"), "eng", false); result = ocr.DoOCR(map, Rectangle.Empty); foreach (tessnet2.Word word in result) { txt += word.Text; } Console.WriteLine(txt); Console.ReadLine(); } catch (Exception ex) { } return Content(txt); } public ActionResult About() { return View(); } } }
View Code

 

 

转载地址:http://owwnl.baihongyu.com/

你可能感兴趣的文章
EntityFramework外健的读写
查看>>
codeforces Gym 100500 J. Bye Bye Russia
查看>>
想做Android Wear开发?你得先搞明白这四件事
查看>>
js基础进阶--promise和setTimeout执行顺序的问题
查看>>
mongoose再认识(三)
查看>>
你真的了解RPC吗?
查看>>
Composer简明教程
查看>>
jsonP格式接口实现
查看>>
INDIGO STUDIO神器!快速创建WEB、移动应用的交互原型工具【转】
查看>>
我的2017云栖之行
查看>>
HSQLDB安装与使用方法
查看>>
重拾C++之初始化
查看>>
maven nexus 下发布第三方构件;
查看>>
Java学习之深拷贝浅拷贝及对象拷贝的两种方式
查看>>
如何根据动态SQL代码自动生成DTO
查看>>
html input="file" 浏览时只显示指定文件类型 xls、xlsx、csv
查看>>
Android Export aborted because fatal error were fo
查看>>
在window平台下模拟Liunx使用GCC环境进行编译C的SO库。
查看>>
原来一直纠结MQ的用法,今天看到了一个最经典的例子。
查看>>
Resource is out of sync with the file system的解决办法
查看>>