基本信息
源码名称:C#识别图片文字(tesseract OCR )
源码大小:41.31M
文件格式:.zip
开发语言:C#
更新时间:2019-03-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

利用谷歌开源tesseract的dll组件,在VS平台上,用C#语言实现对图片中字符的识别,在图片较规整的情况下,可识别字母数字。

【注意事项】


关于软件的使用win7及一下的电脑上运行需要安装.net framework4.0,另外该程序对只包含文本,且文本清晰的图片识别率较高,另外随着文字的增多识别的成功率会下降。

 

该软件采用的是Tesseract及其配套的训练库来实现图片中的文字识别(包括中文)

如果读者要自己创建同样识别程序需要注意的地方有以下几点:

1、 需要文件有:Tesseract.dllchi_sim.traineddata这两个文件在该项目目录下均可以找到。

2、 项目目标处理器必须设置为x86,不然运行不通过

3、 使用时,将Tesseract.dll添加项目引用中。如果准备使用.net4.0框架主要修改app.config文件中的app.config一致。如果不想修改app.config,请将项目.net框架降低3.5版本,否则编译时出错。

4、 主要识别过程如下

Bitmap bmp = new Bitmap(textBox_Path.Text);

TesseractProcessor process = new TesseractProcessor();

process.SetPageSegMode(ePageSegMode.PSM_SINGLE_LINE);

process.Init(System.Environment.CurrentDirectory "\\","chi_sim", (int)eOcrEngineMode.OEM_DEFAULT);

string result = process.Recognize(bmp);

MessageBox.Show("识别结果为:" result);

其中process.Init函数的第一个参数为chi_sim.traineddata的路径,本项目中为软件运行目录下(记着把文件放在指定目录下,不然运行会出错的),记得最后还有反斜杠第二个参数为训练名不带扩展名的。第三个参数不用管,原封抄下就可以了。

5、 另外注意文件chi_sim.traineddata是训练库文件,如果觉得识别率不高可以自己再网上找Tesseract的训练库,替换该文件


using OCR.TesseractWrapper;
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;

namespace 识别汉字
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(textBox_Path.Text);
            TesseractProcessor process = new TesseractProcessor();
            process.SetPageSegMode(ePageSegMode.PSM_SINGLE_LINE);
            process.Init(System.Environment.CurrentDirectory "\\","chi_sim", (int)eOcrEngineMode.OEM_DEFAULT);
            string result = process.Recognize(bmp);
            MessageBox.Show("识别结果为:   " result);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "(*.jpg,*.gif,*.bmp,*.png,*.jpeg)|*.JPG;*.GIF;*.BMP;*.PNG;*.JPEG";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                textBox_Path.Text = ofd.FileName;
                Bitmap bmp = new Bitmap(textBox_Path.Text);
                pictureBox_Oraginal.Image = bmp;
            }
        }
    }
}