原标题:LEADTOOLS OCR文字识别教程:开始文字识别
在前面的教程中,我们教会大家如何追加页面和在页面上追加删除区域,这一次我们正式开始文字识别。
1. 打开Visual Studio,然后打开上一讲中我们创建的项目OCRTurorial2。
2. 从工具箱中拖拽一个Button到Form1中,保持Button的名字为" button6",然后将Button的Text文本改为: 识别并保存。
3. 双击button6,然后在Click事件中添加如下代码:
private void button6_Click(object sender, EventArgs e){// 这里启动识别所有页面// 注意,我们并没有使用自动识别区域这个方法,识别引擎会检查当前页面// 是否已经标示过识别区域了,如果没有的话引擎会自动帮我们标示识别区域_ocrDocument.Pages.Recognize(null);// 弹出保存为PDF对话框string fileName = null;using (SaveFileDialog dlg = new SaveFileDialog()){dlg.Filter = "PDF files|*.pdf|All files|*.*";dlg.DefaultExt = "pdf";if (dlg.ShowDialog(this) == DialogResult.OK)fileName = dlg.FileName;}if (fileName == null)return;// 将识别结果保存为PDF文件_ocrDocument.Save(fileName, DocumentFormat.Pdf, null);// 调用系统命令打开保存的PDF文件System.Diagnostics.Process.Start(fileName);}
4. 编译并运行。
识别结果:
源码下载: OcrTutorial2.zip返回搜狐,查看更多
责任编辑: