C# 图片识别(支持21种语言)

news/2024/7/10 4:16:03 标签: c#, 语言, office, path, layout, image

原文链接

http://www.cnblogs.com/stone_w/archive/2011/10/08/2202397.html#2472415


图片识别的技术到几天已经很成熟了,只是相关的资料很少,为了方便在此汇总一下(C#实现),方便需要的朋友查阅,也给自己做个记号。


图片识别的用途:很多人用它去破解网站的验证码,用于达到自动刷票或者是批量注册的目的,但我觉得它最吸引我的地方是可以让一些书写的东西,自动识别成电脑上的文字,比如说手拟的合同,修改过的书面论文或者是文档,每月的花费发票需要在电脑上录入或者是汇总信息,日记本上的文章要转移到电脑上等等,我们现在就不用再头痛把它们在电脑上敲写一遍了。

images/2011/172074/2011100818251535.png" alt="" style="margin: 0px; padding: 0px; border: 0px; " />

本文介绍两种比较主流和成熟的识别方式:

方式一、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:为图片路径,startXstartY坐标均为0即可,widthheight图片的宽和高。


方式二、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 


给项目添加组件引用,如图:

images/2011/172074/2011100818253883.png" alt="" style="margin: 0px; padding: 0px; border: 0px; " />

使用代码:

MODI.Document doc = new MODI.Document();

doc.Create(img_Path);

MODI.Image image;

MODI.Layout layout;

doc.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, truetrue);  // 识别简体中文

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为读取图片的文字类型枚举。


本文源码下载地址:http://files.cnblogs.com/stone_w/OCR.rar 


汉王 PDF OCR V8.1简体中文版下载地址(已经使用了,感觉不错推荐一下)http://xiazai.zol.com.cn/detail/34/335364.shtml 

image: url(http://images.cnblogs.com/cnblogs_com/lloydsheng/239039/o_copyright.gif); background-color: rgb(229, 241, 244); font-family: 微软雅黑; font-size: 11px; background-position: 1% 50%; background-repeat: no-repeat no-repeat; ">
作者:西安.王磊 
出处:http://stone_w.cnblogs.com/ 
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 


http://www.niftyadmin.cn/n/1411304.html

相关文章

递归算法时间复杂度分析与改善

递归算法大家都不陌生&#xff0c;当须要反复计算同样问题时&#xff0c;一般能够选择递归和循环两种算法。又由于递归实现起来代码比較简洁。所以通常都会使用递归来解决上述问题。比方斐波那契数列。再比方树的前序、中序、兴许遍历算法。 递归算法尽管是有代码简洁这个长处&…

初学Android,创建,启动,停止Service(五十八)

Service跟Windows系统里的服务概念差不多&#xff0c;都在后台执行&#xff0c;它跟Activity的最大区别就是&#xff0c;它是无界面的 开发Service与开发Activity的步骤类似 1.定义一个继承Service的子类 2.在AndroidManifest.xml文件中配置该Service Service与Activity还有一点…

zepto源码研究(1)$到底如何实现?

在zepto中&#xff0c;$作为一个选择器而存在&#xff0c;它接收一个字符串&#xff0c;返回一个选择器的数组,并且这个数组有一个属性&#xff0c;叫selector。 通过研究源码&#xff0c;zepto的实现步骤有这么几步&#xff1a; 第一步&#xff0c;定义了一个 $ 的变量&am…

Mac安装tomcat及tomcatPlugin插件

Mac 安装tomcat,和tomcat插件步骤 很多刚使用Mac系统来运行eclipse 在安装tomcat时会头疼虽然现在我使用IDEA前两天帮以前的同事在Mac上安装tomcat以及tomcat插件,现在把具体步骤分享遇到此类问题的码友们如果帮到你们请关注我的简书并且点赞目的:tomcat服务器及tomcat插件的安…

初学Android,绑定本地Service并与之通信(五十九)

如果Service和访问者之间需要进行方法调用或数据交换,则需要使用bindService()和unbindService()方法启动&#xff0c;关闭服务BindService和Started Service都是Service&#xff0c;有什么地方不一样呢&#xff1a;1. Started Service中使用StartService&#xff08;&#xff…

Spring Boot 之 RestTemplate 网络请求实践

引入依赖<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.2.RELEASE</version><relativePath/> <!-- lookup parent from repository --></p…

bind方法的实现

bind方法的作用&#xff1a;就是进行this绑定。他的返回值是一个函数&#xff0c;返回的函数中的this就是bind的参数对象。 可以这样的进行简单的实现&#xff1a; function bind(fn, context){return function(){return fn.apply(context,arguments);} } 在原生JavaScript中…

初学Android,跨进程调用Service(六十)

Android系统中&#xff0c;各应用程序都运行在自己的进程中&#xff0c;进程之间一般无法进行数据交换。 Android调用Service先定义一个远程调用接口&#xff0c;然后为该接口提供一个实现类。Android访问Service时&#xff0c;不是直接返回Service对象给客户端——Service只是…