C# 光学字符识别(OCR) / English

光学字符识别的原理大致与我的这篇帖子内讲述的“验证码识别”大同小异

当然本文并不阐述验证码识别的原理

在网上有很多不同的类库与接口提供光学字符识别,如百度接口商店

(Baidu API Store)中提供不少的识别库,但主要是REST API接口方式

在本文中我使用轻量高效的AspriseOCR,著名的光学字符识别引擎

有Google的Tesseract,Microsoft的PPT光学字符识别引擎也包括

“OpenCV / EmguCV”新视觉识别引擎 但是两者庞大体积令人望却生畏

        private abstract class NativeMethod
        {
            [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)]
            public static extern IntPtr OCRpart(string file, int type, int startX, int startY, int width, int height);

            [DllImport("AspriseOCR.dll", EntryPoint = "OCRBarCodes", CallingConvention = CallingConvention.Cdecl)]
            public static extern IntPtr OCRBarCodes(string file, int type);

            [DllImport("AspriseOCR.dll", EntryPoint = "OCRpartBarCodes", CallingConvention = CallingConvention.Cdecl)]
            public static extern IntPtr OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height);

            public static readonly IntPtr NULL = IntPtr.Zero;
        }
上面是AspriseOCR导出的几个函数,当然还有一个函数是

_Java_com_asprise_util_ocr_OCR_performOCR@16

它主要是用于JAVA的光学字符识别交互调用的函数 对C#

而言没有任何实际意义

函数示意:

OCR(string file, int type); 光学字符识别(文件名,识别类型);

OCRpart(string file, int type, int startX, int startY, int width, int height); 光学字符部分识别(文件名,识别类型,起始横坐标,起始竖坐标,高度,宽度);

OCRBarCodes(string file, int type); 光学条形码识别(文件名,识别类型);

OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height); 光学条形码识别(文件名,识别类型,起始横坐标,起始竖坐标,高度,宽度);

注:返回值为ASCII字符集的头指针,当函数被调用时,会独占文件识别完毕后自动释放掉被占用的文件

C# 光学字符识别(OCR) / English_第1张图片

从上图可以看到AspriseOCR的精度相当高,当然这是在没有受到干扰的情况下

及时光学字符识别(OCR)发展了几十年但是对干扰的抵抗力一直无法得到突破性

进展,当然我们只有关注关注就行了 呵呵、

C# 光学字符识别(OCR) / English_第2张图片

识别字符部分的代码,相当的简单这也是我选择这个OCR库写本文的理由、

不过需要注意的事是,如果你使用AspriseOCR的话 那么你的项目运行的

平台必须限制在X86,没办法该库不支持X64准确的说是该库是在X86上开

发 可以使用更少的内存 兼容更多的PC、

C# 光学字符识别(OCR) / English_第3张图片

好了,用AspriseOCR字符识别引擎能写的基本上已经没有了,该说的

该注明的我也写了,那么把开源示例代码贴出来吧 

示例代码:http://pan.baidu.com/s/1i3CoYqD


你可能感兴趣的:(C#)