C#OCR图片识别
2014-02-24 10:19
218 查看
图片识别的技术到几天已经很成熟了,只是相关的资料很少,为了方便在此汇总一下(C#实现),方便需要的朋友查阅,也给自己做个记号。
图片识别的用途:很多人用它去破解网站的验证码,用于达到自动刷票或者是批量注册的目的,但我觉得它最吸引我的地方是可以让一些书写的东西,自动识别成电脑上的文字,比如说手拟的合同,修改过的书面论文或者是文档,每月的花费发票需要在电脑上录入或者是汇总信息,日记本上的文章要转移到电脑上等等,我们现在就不用再头痛把它们在电脑上敲写一遍了。
本文介绍两种比较主流和成熟的识别方式:
方式一、Asprise-OCR实现。
方式二、Microsoft Office Document Imaging(Office 2007) 组件实现。
方式一、Asprise-OCR的使用。
Asprise-OCR下载地址:
http://asprise.com/product/ocr/download.php?lang=csharp
其中需要使用的3个dll是AspriseOCR.dll、DevIL.dll、ILU.dll。
需要注意的是这几个.dll是vc写的引用要在程序中用DllImport引用,关键代码:
[DllImport("AspriseOCR.dll", EntryPoint = "OCR", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr OCR(string file, int type);
[DllImport("AspriseOCR.dll", EntryPoint = "OCRpart", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr OCRpart(string file, int type, int startX, int startY, int width, int height);
[DllImport("AspriseOCR.dll", EntryPoint = "OCRBarCodes", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr OCRBarCodes(string file, int type);
[DllImport("AspriseOCR.dll", EntryPoint = "OCRpartBarCodes", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height);
调用代码很简单只有一句:
MessageBox.Show(Marshal.PtrToStringAnsi(OCRpart(img_path, -1, startX, startY, width, height)));
其中img_path:为图片路径,startX、startY坐标均为0即可,width、height图片的宽和高。
方式二、Microsoft Office Document Imaging(Office 2007) 组件实现。
在使用之前需要给大家说的是Imaging 组件的兼容性不是很好,使用win 7 office 2007的时必须打上office 2007 sp1或者sp2补丁,读取中文才行。
sp1补丁地址(226M) :
http://download.microsoft.com/download/1/6/5/1659d607-8696-4001-8072-efaedd70dd30/office2007sp1-kb936982-fullfile-zh-cn.exe
sp2补丁地址(301 MB):
http://download.microsoft.com/download/A/3/9/A39E919E-AFA8-4128-9249-51629206C70F/office2007sp2-kb953195-fullfile-zh-cn.exe
给项目添加组件引用,如图:
使用代码:
MODI.Document doc = new MODI.Document();
doc.Create(img_Path);
MODI.Image image;
MODI.Layout layout;
doc.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, true, true); // 识别简体中文
for (int i = 0; i < doc.Images.Count; i++)
{
image = (MODI.Image)doc.Images[i];
layout = image.Layout;
sb.Append(layout.Text);
}
MessageBox.Show(sb.ToString());
其中img_Path为图片路径,MODI.MiLANGUAGES为读取图片的文字类型枚举。
图片识别的用途:很多人用它去破解网站的验证码,用于达到自动刷票或者是批量注册的目的,但我觉得它最吸引我的地方是可以让一些书写的东西,自动识别成电脑上的文字,比如说手拟的合同,修改过的书面论文或者是文档,每月的花费发票需要在电脑上录入或者是汇总信息,日记本上的文章要转移到电脑上等等,我们现在就不用再头痛把它们在电脑上敲写一遍了。
本文介绍两种比较主流和成熟的识别方式:
方式一、Asprise-OCR实现。
方式二、Microsoft Office Document Imaging(Office 2007) 组件实现。
方式一、Asprise-OCR的使用。
Asprise-OCR下载地址:
http://asprise.com/product/ocr/download.php?lang=csharp
其中需要使用的3个dll是AspriseOCR.dll、DevIL.dll、ILU.dll。
需要注意的是这几个.dll是vc写的引用要在程序中用DllImport引用,关键代码:
[DllImport("AspriseOCR.dll", EntryPoint = "OCR", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr OCR(string file, int type);
[DllImport("AspriseOCR.dll", EntryPoint = "OCRpart", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr OCRpart(string file, int type, int startX, int startY, int width, int height);
[DllImport("AspriseOCR.dll", EntryPoint = "OCRBarCodes", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr OCRBarCodes(string file, int type);
[DllImport("AspriseOCR.dll", EntryPoint = "OCRpartBarCodes", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height);
调用代码很简单只有一句:
MessageBox.Show(Marshal.PtrToStringAnsi(OCRpart(img_path, -1, startX, startY, width, height)));
其中img_path:为图片路径,startX、startY坐标均为0即可,width、height图片的宽和高。
方式二、Microsoft Office Document Imaging(Office 2007) 组件实现。
在使用之前需要给大家说的是Imaging 组件的兼容性不是很好,使用win 7 office 2007的时必须打上office 2007 sp1或者sp2补丁,读取中文才行。
sp1补丁地址(226M) :
http://download.microsoft.com/download/1/6/5/1659d607-8696-4001-8072-efaedd70dd30/office2007sp1-kb936982-fullfile-zh-cn.exe
sp2补丁地址(301 MB):
http://download.microsoft.com/download/A/3/9/A39E919E-AFA8-4128-9249-51629206C70F/office2007sp2-kb953195-fullfile-zh-cn.exe
给项目添加组件引用,如图:
使用代码:
MODI.Document doc = new MODI.Document();
doc.Create(img_Path);
MODI.Image image;
MODI.Layout layout;
doc.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, true, true); // 识别简体中文
for (int i = 0; i < doc.Images.Count; i++)
{
image = (MODI.Image)doc.Images[i];
layout = image.Layout;
sb.Append(layout.Text);
}
MessageBox.Show(sb.ToString());
其中img_Path为图片路径,MODI.MiLANGUAGES为读取图片的文字类型枚举。
相关文章推荐
- C#调用OCR组件识别图片文字
- C# 图片识别asprise-ocr使用步骤
- C#OCR图片识别
- C# 使用Microsoft Office Document Imaging(MODI) 识别 图片中的文字(OCR)
- OCR图片识别
- C# tessnet2.Tesseract识别图片验证码内容
- Android实现OCR扫描识别数字图片之图片扫描识别
- tesseract-ocr 实现图片识别功能
- 用于验证码图片识别的类续(C#代码)
- C#识别图片上的数字
- 简单验证码图片识别BMP,C,C++,C#,JAVA,脚本-网络攻防大赛笔记(1)
- 用于验证码图片识别的类(C#源码)
- tesseract-ocr图片识别开源工具
- tesseract 4.0 ocr图像识别利器,可识别文字。图片越高清越准确
- C# 图片识别(支持21种语言)
- C# 图片识别(支持21种语言)
- java 图片文字识别 ocr
- 基于OCR的图片字符识别可行性研究
- 用于验证码图片识别的类(C#源码)
- c#实现识别图片上的验证码数字