在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#图形和图像处理 → OCR 实现 截图 并提取图片中的文字实例 附完整源码

OCR 实现 截图 并提取图片中的文字实例 附完整源码

C#图形和图像处理

下载此实例
  • 开发语言:C#
  • 实例大小:0.20M
  • 下载次数:245
  • 浏览次数:9602
  • 发布时间:2013-04-17
  • 实例类别:C#图形和图像处理
  • 发 布 人:crazycode
  • 文件格式:.rar
  • 所需积分:2
 相关标签: OCR 图片 截图

实例介绍

【实例简介】该实例实现了 截图并识别截图中的文字功能

该项目需要在安装 Microsoft Office Document Imaging

下载地址 如下: http://www.xdowns.com/soft/4/25/2009/Soft_50716.html 


【实例截图】

点击Capture之后 开始截图,截图的结果显示在如下窗体中

与此同时 将截图中的文字提取到下面的文本框中


【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;

namespace DevOCR
{
	public partial class ShowBitmap : Form
	{

        //这个Bitmap对象存储
        //选择位图。
		public Bitmap m_objBitmap;

		public ShowBitmap()
		{
			InitializeComponent();
		}

        // This just draws the bitmap in the window.这只是绘制位图的窗口。
		private void OnPaint(object sender, PaintEventArgs e)
		{
			e.Graphics.DrawImage(m_objBitmap, 0, 0);
		}

        // We come here when the dialog has first appeared.我们来到这里时,对话框已首次出现。
		private void timer1_Tick(object sender, EventArgs e)
		{
			// Turn the timer off so we don't
			//   do this multiple times.
            //打开计时器关闭,因此我们不
            //这样做多次。
			timer1.Enabled = false;

            // Ask user if this is what they want to do.问问用户如果这是他们想做的事情。
			if (MessageBox.Show("Convert this to text?",
				"Convert?", MessageBoxButtons.OKCancel) == DialogResult.OK)
			{
                // Create a temp file name.创建一个临时文件的名称。
				string strFileName = "temp"   DateTime.Now.Millisecond   ".tif";
				try
				{
                    // Save the bitmap object to a tiff file.位图对象保存到一个TIFF文件。

                    Console.WriteLine(m_objBitmap.PixelFormat.ToString()); 
					m_objBitmap.Save(strFileName, ImageFormat.Tiff);

                    // Instantiate the MODI.Document object实例MODI.Document对象
					MODI.Document md = new MODI.Document();
					// The Create method grabs the picture from
					//   disk snd prepares for OCR.Create
                    //方法从抓起图片
                    //磁盘新区准备的光学字符识别。
					md.Create(strFileName);
					// Do the OCR.运行OCR
					md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);

                    // This string will contain the text.这个字符串将包含文本。
					string strText = String.Empty;

                    // Get the first (and only image)获得第一个(也是唯一图片)
					MODI.Image image = (MODI.Image)md.Images[0];
                    // Get the layout.获取布局。
					MODI.Layout layout = image.Layout;

					// Loop through the words.遍历文字
					for (int j = 0; j < layout.Words.Count; j  )
					{
						// Get this word.得到得到文字
						MODI.Word word = (MODI.Word)layout.Words[j];
                        // Add a blank space to separate words.添加一个空格来分隔文字。
						if (strText.Length > 0)
						{
							strText  = " ";
						}
						// Add the word.添加文字
						strText  = word.Text;
					}
                    // Close the MODI.Document object.关闭MODI.Document对象。
					md.Close(false);
                    // Create the dialog that displays创建对话框显示
                    //   the OCRed text.文本的文本识别。
					ShowText st = new ShowText();
                    // The the dialog's text.该对话框的文本。
					st.m_strOCRText = strText;
                    // Show the dialog.显示的对话框。
					st.ShowDialog();
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message.ToString());
				}
				try
				{
                    // Delete the temp file.删除临时文件。
					File.Delete(strFileName);
				}
				catch { }
			}
            // Close this dialog.关闭此对话框。
			Close();
		}
	}
}

标签: OCR 图片 截图

实例下载地址

OCR 实现 截图 并提取图片中的文字实例 附完整源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 tyw 发表于: 2014-04-04 13:23 38
很期待,等有了积分再来

支持(0) 盖楼(回复)

第 2 楼 gdg2046@163.com 发表于: 2016-05-12 17:42 47
这个真是好东西,想研究研究

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有2条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警