图片识别的技术到几天已经很成熟了,只是相关的资料不多,为了方便在此汇总一下(C#实现),方便须要的朋友查阅,也给本身作个记号。php
图片识别的用途:不少人用它去破解网站的验证码,用于达到自动刷票或者是批量注册的目的,但我以为它最吸引个人地方是可让一些书写的东西,自动识别成电脑上的文字,好比说手拟的合同,修改过的书面论文或者是文档,每个月的花费发票须要在电脑上录入或者是汇总信息,日记本上的文章要转移到电脑上等等,咱们如今就不用再头痛把它们在电脑上敲写一遍了。html
本文介绍两种比较主流和成熟的识别方式:post
方式1、Asprise-OCR实现。网站
方式2、Microsoft Office Document Imaging(Office 2007) 组件实现。spa
方式1、Asprise-OCR的使用。orm
Asprise-OCR下载地址:htm
http://asprise.com/product/ocr/download.php?lang=csharp blog
其中须要使用的3个dll是AspriseOCR.dll、DevIL.dll、ILU.dll。图片
须要注意的是这几个.dll是vc写的引用要在程序中用DllImport引用,关键代码:ip
[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图片的宽和高。
方式2、Microsoft Office Document Imaging(Office 2007) 组件实现。
在使用以前须要给你们说的是Imaging 组件的兼容性不是很好,使用win 7 office 2007的时必须打上office 2007 sp1或者sp2补丁,读取中文才行。
sp1补丁地址(226M) :
sp2补丁地址(301 MB):
给项目添加组件引用,如图:
使用代码:
MODI.Document doc = new MODI.Document();
doc.Create(img_Path);
MODI.Image image;
MODI.Layout