zoukankan      html  css  js  c++  java
  • 利用tessnet2_32.dll实现OCR验证码识别

    using System;
    using System.Collections.Generic;
    using System.Web;
    //add
    using System.Net;
    using System.IO;
    using tessnet2; //引用tessnet2_32.dll
    using System.Drawing;
    using GetCodes;
    using System.Text;
    
    public partial class OCR : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            WebRequest request = WebRequest.Create("http://sz.2zf.cn/js/code2.asp");
            WebResponse response = request.GetResponse();
            Stream st = response.GetResponseStream();
            Bitmap bitmap = (Bitmap)Bitmap.FromStream(st);
            UnCodebase ud = new UnCodebase(bitmap);
            bitmap = ud.GrayByPixels();
            ud.ClearNoise(128, 2);
    
            //保存显示
            string savepath = "~/photos/orc.gif";
    
            bitmap.Save(Server.MapPath(savepath), System.Drawing.Imaging.ImageFormat.Gif);
            Image1.ImageUrl = savepath;
    
            tessnet2.Tesseract ocr = new tessnet2.Tesseract();//声明一个OCR类 
            ocr.SetVariable("tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); //设置识别变量 
            //ocr.Init(null, "eng", false);
            ocr.Init(Server.MapPath("~/Language"), "eng", true); //应用当前语言包。注,Tessnet2是支持多国语的。语言包下载链接:http://code.google.com/p/tesseract-ocr/downloads/list 
            List<tessnet2.Word> result = ocr.DoOCR(bitmap, Rectangle.Empty);//执行识别操作 
            string code = result[0].Text;
            Label1.Text = code;
        }
    }

  • 相关阅读:
    JVisualVM远程监控
    周记 2014.11.22
    读取配置文件
    周记 2014.11.15
    MyBatis 逆向工程介绍
    PyTorch模型加载与保存的最佳实践
    ubuntu 服务器 php 环境简单搭建
    【重温广州读书会三青年自白,想念在深圳建会工人斗争中积极声援的他们!!】
    EventBus 3.0 的基本使用
    搭建Hexo博客
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234336.html
Copyright © 2011-2022 走看看