C# WINFORM OCR识别功能

本文介绍了如何使用C# Winform实现OCR文字识别,通过转换图片为Tiff格式,并调用MODI库进行英文识别。同时,讲解了如何实现在应用程序中进行屏幕截图,包括全屏拷贝和自定义区域截图。代码示例详细展示了截图的绘制和位置交换逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

组件--- Microsoft Office Document Imaging;这样就方便的做OCR识别了。
首先用office安装盘安装这个组件,默认安装office的时候是不会安装的,只要添加这个组件功能就好了。
然后新建的项目里添加组件Microsoft Office Document Imaging 12.0 Type Library(office07)或者Microsoft Office Document Imaging 11.0 Type Library(office03)
MODI.Document md = new MODI.Document();

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            md.Create(Directory.GetCurrentDirectory() + "\\SampleForOCR.tiff");

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            MODI.Image image = (MODI.Image)md.Images[0];

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            MODI.Layout layout = image.Layout;

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            MODI.Word word;

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            StringBuilder sb = new StringBuilder();

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            for (int i = 0; i 

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂{

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂                word = (MODI.Word)layout.Words[i];

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂                sb.Append(word.Text);

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            }

sb.ToString就可以得到了

图片转成 tiff

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂Bitmap bitmap = new Bitmap(100, 100);

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            bitmap.Save("somefilename", ImageFormat.Tiff);

如何进行截屏呢?

拷屏.先把整个屏幕的图像拷过来(其它地方也会用到这个.比如做一个操作动作的外挂等)

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂Graphics g = Graphics.FromImage(m_WindowDlg.m_objBitmap);

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            // Copy the screen into the bitmap object.

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            g.CopyFromScreen(0, 0, 0, 0, new Size(w, h));

指定区域是利用

另一个窗口来的..把这个窗口的透明属性opacity设为100%这样人家就看不到了.

然后利用 MouseDown 画出我们截屏的范围 和 mouseUP事件.

mouseUP后引发一个完成的事件.并通知座标大小

主要代码

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂// Make sure we clicked the mouse button and

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            //   have a starting coordinate.

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            if (m_nStartX != -1)

使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂            使用 office2003 document imaging control 控件 做识别 OCR  - Jarod.Zero.D - 无道的自学天堂{

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值