• 大小: 1.76MB
    文件类型: .rar
    金币: 2
    下载: 8 次
    发布日期: 2021-04-06
  • 语言: C#
  • 标签: OCR  TessnetOcr  Tessnet2  

资源简介

OCR数字识别实例,本实例采用TessnetOcr,对数字的识别率100%。可以用于破解简单二维码验证,对环境要求底。.net framework 2.0以上都可以使用,仅供学习参考

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using tessnet2;

namespace TessnetOcrDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //Tessnet2 OCR 官方地址:www.pixel-technology.com/freeware/tessnet2/
            //本实例语言包只可识别数字数学符号,其他文字牵扯语言问题。要了解全面的可以到官方下载,需要翻墙
        }

        private void Form1_Load(object sender EventArgs e)
        {
            //没有选择图片时不可以点击识别按钮
            btnOcr.Enabled = false;
        }

        private void btnOpenImage_Click(object sender EventArgs e)
        {
            try
            {
                Bitmap m_Bitmap;    //定义个Bitmap型变量存储图片
                OpenFileDialog openFileDialog = new OpenFileDialog();    //打开图片
                openFileDialog.Filter = “Bitmap文件(*.bmp)|*.bmp|Jpeg文件(*.jpg)|*.jpg|所有合适文件(*.bmp/*.jpg)|*.bmp/*.jpg“;    //设置图片类型
                openFileDialog.FilterIndex = 1;    //打开对话框中默认第一个类型(即上面的Bitmap文件(*.bmp)|*.bmp)
                openFileDialog.RestoreDirectory = true;    //记录最后一次打开的文件路径
                if (DialogResult.OK == openFileDialog.ShowDialog())//确定打开文件
                {
                    m_Bitmap = (Bitmap)Bitmap.FromFile(openFileDialog.FileName false);    //通过(Bitmap)将打开的图片类型转换
                    imageView.Image = m_Bitmap;    //为pictureBox控件加载所打开的图片
                    AutoScroll = true;
                    AutoScrollMinSize = new Size((int)(m_Bitmap.Width) (int)m_Bitmap.Height);
                    btnOcr.Enabled = true;    //在pictureBox控件中有图片时buttonGenerate按钮可用
                }
            }
            catch (Exception exx)
            {
                MessageBox.Show(exx.Message);
            }
        }

        private void btnOcr_Click(object sender EventArgs e)
        {
            Bitmap image = (Bitmap)imageView.Image;
            String ready_orc_word = textReady.Text;
            if (ready_orc_word.Length<=0)
            {
                //防止错误操作或恶意测试
                ready_orc_word = “0123456789.-+=“;
            }

            Tesseract ocr = new Tesseract();
            ocr.SetVariable(“tessedit_char_whitelist“ ready_orc_word); // If digit only

            ocr.Init(Environment.CurrentDirectory + “\\TessnetOcrData“ “eng“ true);//添加语言包数据引用,最新数据可以到官方下载

            try
            {
                var result = ocr.DoOCR(image Rectangle.Empty);
                string temp = ““;
                foreach (Word word in result)
                {
                    temp += word.Text + “\r\n“;
                }
                textResult.Text = temp;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6096  2019-10-17 18:09  测试图片\1.jpg

     文件      28470  2019-10-17 14:58  测试图片\2.bmp

     文件      97910  2019-10-17 18:12  测试图片\3.bmp

     文件      97910  2019-10-18 15:02  测试图片\4.bmp

     文件        884  2019-10-18 14:21  TessnetOcrDemo.sln

     文件    1455104  2009-09-02 09:54  TessnetOcrDemo\bin\Debug\tessnet2_32.dll

     文件        392  2007-06-01 00:15  TessnetOcrDemo\bin\Debug\TessnetOcrData\eng.DangAmbigs

     文件        672  2007-06-01 00:15  TessnetOcrDemo\bin\Debug\TessnetOcrData\eng.freq-dawg

     文件     862544  2007-06-09 07:33  TessnetOcrDemo\bin\Debug\TessnetOcrData\eng.inttemp

     文件      39862  2007-06-09 07:33  TessnetOcrDemo\bin\Debug\TessnetOcrData\eng.normproto

     文件        590  2007-06-09 07:33  TessnetOcrDemo\bin\Debug\TessnetOcrData\eng.pffmtable

     文件        480  2007-06-01 00:15  TessnetOcrDemo\bin\Debug\TessnetOcrData\eng.unicharset

     文件       7289  2007-05-11 02:17  TessnetOcrDemo\bin\Debug\TessnetOcrData\eng.user-words

     文件     809728  2007-06-01 00:15  TessnetOcrDemo\bin\Debug\TessnetOcrData\eng.word-dawg

     文件      11776  2019-10-18 14:53  TessnetOcrDemo\bin\Debug\TessnetOcrDemo.exe

     文件      26112  2019-10-18 14:53  TessnetOcrDemo\bin\Debug\TessnetOcrDemo.pdb

     文件      11608  2019-10-18 14:56  TessnetOcrDemo\bin\Debug\TessnetOcrDemo.vshost.exe

     文件        490  2017-04-11 11:11  TessnetOcrDemo\bin\Debug\TessnetOcrDemo.vshost.exe.manifest

     文件       3345  2019-10-18 15:01  TessnetOcrDemo\Form1.cs

     文件       6589  2019-10-18 14:59  TessnetOcrDemo\Form1.Designer.cs

     文件       5817  2019-10-18 14:59  TessnetOcrDemo\Form1.resx

     文件       6230  2019-10-18 14:53  TessnetOcrDemo\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        893  2019-10-18 14:56  TessnetOcrDemo\obj\x86\Debug\TessnetOcrDemo.csproj.FileListAbsolute.txt

     文件        975  2019-10-18 14:47  TessnetOcrDemo\obj\x86\Debug\TessnetOcrDemo.csproj.GenerateResource.Cache

     文件       7013  2019-10-18 14:47  TessnetOcrDemo\obj\x86\Debug\TessnetOcrDemo.csprojResolveAssemblyReference.cache

     文件      11776  2019-10-18 14:53  TessnetOcrDemo\obj\x86\Debug\TessnetOcrDemo.exe

     文件        180  2019-10-18 14:47  TessnetOcrDemo\obj\x86\Debug\TessnetOcrDemo.Form1.resources

     文件      26112  2019-10-18 14:53  TessnetOcrDemo\obj\x86\Debug\TessnetOcrDemo.pdb

     文件        180  2019-10-18 14:47  TessnetOcrDemo\obj\x86\Debug\TessnetOcrDemo.Properties.Resources.resources

     文件        495  2019-10-18 14:22  TessnetOcrDemo\Program.cs

............此处省略21个文件信息

评论

共有 条评论