赞
踩
基于OCRTessnet图像识别
首先下载OCRTessnet库文件和语言包。点击下载
在项目中添加库文件tessnet2-64的引用
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication6 { using System.Drawing; using tessnet2; public partial class OCRTessnet : Form { public string imgPath; private Bitmap image; private Tesseract ocr; public OCRTessnet(string imgPath) { InitializeComponent(); this.imgPath = imgPath; imgPath = @"F:\doc\cLibrary\C#\2.png"; //识别目标图片 image = new Bitmap(imgPath); //image = new Bitmap(@"C:\OCRTest\number.jpg"); ocr = new Tesseract(); ocr.SetVariable("tessedit_char_whitelist", "0123456789"); // If digit only //@"C:\OCRTest\tessdata" contains the language package, without this the method crash and app breaks ocr.Init(@"F:\doc\cLibrary\tessdata", "eng", true);//添加语言包引用 pbResult.ImageLocation = imgPath; } private void btnTessnet_Click(object sender, EventArgs e) { try { var result = ocr.DoOCR(image, Rectangle.Empty); string temp=""; foreach (Word word in result) temp += word.Text+ "\r\n"; tbResult.Text = temp; } catch (Exception exception) { } } private void pbResult_Click(object sender, EventArgs e) { } private void btnBack_Click(object sender, EventArgs e) { backMain(); } private void backMain() { Form1 form1 = new Form1(); this.Hide(); form1.Show(); } } }
下边是运行结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。