实例介绍
【实例简介】
英文识别率百分之99以上,中文识别率百分之30左右,如果自己有庞大的数据库可提升识别率, 源码内有 识别中文,英文 数字等区别,自行更改, 单一英文加数字识别率是最高的
该项目需要在安装 Microsoft Office Document Imaging
下载地址 如下: http://www.xdowns.com/soft/4/25/2009/Soft_50716.html
【实例截图】
截图后 识别图中文字
【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Windows;
using System.Drawing.Imaging;
using System.Threading;
namespace DevOCR
{
public partial class Form1 : Form
{
// Declare the two dialog objects
// we'll be using.
//声明的两个对话框对象
//我们将使用。
MyWin m_WindowDlg;
ShowBitmap m_ShowBitmapDlg;
public Form1()
{
InitializeComponent();
}
private void btnCapture_Click(object sender, EventArgs e)
{
// Get the screen width and height.获取屏幕的宽度和高度。
int w = Screen.PrimaryScreen.Bounds.Width;
int h = Screen.PrimaryScreen.Bounds.Height;
// Create the dialog object on which we'll创建对话框对象上,我们将
// display the screen bitmap.在屏幕显示位图。
m_WindowDlg = new MyWin();
// Set to wait cursor so user knows something设置为等待光标,使用户知道的东西
// is going on.是怎么回事。
Cursor = Cursors.WaitCursor;
// Hide the main app window so that it isn't in the隐藏在主应用程序窗口,以便它不是在
// capture image (and wait since Vista takes its time).捕获图像(等待由于Vista需要的时间)。
Hide();
Thread.Sleep(200);
// Create the bitmap into which the screen will be copied.创建到该屏幕将被复制位图。
m_WindowDlg.m_objBitmap = new Bitmap(w, h,
PixelFormat.Format32bppArgb);
// Get the graphics context for the bitmap.获取为位图图形上下文。
Graphics g = Graphics.FromImage(m_WindowDlg.m_objBitmap);
// Copy the screen into the bitmap object.位图复制到对象的屏幕。
g.CopyFromScreen(0, 0, 0, 0, new Size(w, h));
// Show the main application window. We need显示主应用程序窗口。我们需要
// to do this because the child window won't这样做,因为子窗口不会
// behave properly if it's hidden or minimized.循规蹈矩,如果是隐藏或最小化。
Show();
// Create a delegate so that the EndCapture创建一个代表,让EndCapture
// method can be called.方法可以调用。
m_WindowDlg.m_EndCaptureMethod =
new MyWin.EndCaptureMethod(EndCapture);
// Show the captured screen.查看捕获的屏幕。
m_WindowDlg.Show();
// Hide the main application window.隐藏主应用程序窗口。
Hide();
// Set the location, size, and cursor of the设置的位置,大小,以及游标
// dialog in which the user will select对话框中,用户将选择
// a portion.的一部分。
m_WindowDlg.Location = new Point(0, 0);
m_WindowDlg.Size = new Size(w, h);
m_WindowDlg.Cursor = Cursors.Cross;
}
// This method is called once the user is这种方法被称为一旦用户
// finished selecting the screen region完成选择屏幕区域
// that will be OCRed.将文本识别过。
public void EndCapture(int x, int y, int w, int h)
{
// Restore cursor恢复光标
Cursor = Cursors.Default;
// Created the dialog in which we'll创建对话框中,我们将
// show the capture bitmap.显示位图的捕获。
m_ShowBitmapDlg = new ShowBitmap();
// Copy the bitmap from the selection bitmap复制从选择位图位图
// that was displayed to the display bitmap.这是显示在显示位图。
m_ShowBitmapDlg.m_objBitmap =
new Bitmap(w, h, PixelFormat.Format32bppArgb);
// Get the graphics context for the bitmap.获取为位图图形上下文
Graphics g =
Graphics.FromImage(m_ShowBitmapDlg.m_objBitmap);
// Copy the selected portion into the newly-created选定部分复制到新创建的
// bitmap.位图
g.DrawImage(m_WindowDlg.m_objBitmap,
new Rectangle(0, 0, w, h), x, y,
w, h, GraphicsUnit.Pixel);
// Hide the dialog that was used to display the 隐藏了用来显示对话框
// entire screen.整个屏幕。
m_WindowDlg.Hide();
// Add to the width and height the frame margins.增加宽度和高度的框架边缘
w = (m_ShowBitmapDlg.Bounds.Width -
m_ShowBitmapDlg.ClientRectangle.Width);
h = (m_ShowBitmapDlg.Bounds.Height -
m_ShowBitmapDlg.ClientRectangle.Height);
// Set the maximum size for the window in which设置的窗口,其中最大尺寸
// we'll display the bitmap.我们将会显示位图。
m_ShowBitmapDlg.MaximumSize =
m_ShowBitmapDlg.Size = new Size(w, h);
// Show the bitmap in the dialog.查看对话框中的位图。
m_ShowBitmapDlg.ShowDialog();
// Now re-show the main application window.现在重新出现在主应用程序窗口。
Show();
}
}
}
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论