天下之事,必先处之难,而后易之。

C# OCR AspriseOcr测试使用图像文字中英文识别

OCR AspriseOcr测试使用中英文识别:因为使用AspriseOcr是需要商业授权码的,故使用网上破解dll包进行测试,测试的结果并不理想,可能是因为版本太低所致。如果真的需要做好OCR应用建议购买其授权码。

官网地址:http://asprise.com/

应用场景

  • 图像扫描:对图片进行文字识别
  • 文件扫描:对PDF文件进行文字识别
  • 条码扫描:对二维码条码进行扫描识别

测试示例

注意:需要下载的DLL分别是AspriseOCR.dll、DevIL.dll、ILU.dll将其放在生成的bin/Debug生成目录下,然后就可以测试了,网上有人说需要.net 2.0这个是谬传,我用的是.net framwork 4.5 ,DLL包不用放在注册表里去,放在可执行目录即可,程序运行时会自动加载,因为使用的是DllImport方式导入。

定义接口:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OCR
{
    interface ImageRecognitionInterface
    {

        /// <summary>
        /// 识别图像
        /// </summary>
        /// <param name="imgPath"></param>
        /// <returns></returns>
        string Recognize(string imgPath);
    }
}

编写工具类和实现:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace OCR.ImageRecognition
{
    /// <summary>
    /// AspriseOCR
    /// </summary>
    /// DLL包引用:AspriseOCR.dll、DevIL.dll、ILU.dll
    /// 下载地址:http://asprise.com/product/ocr/download.php?lang=csharp
    public class AspriseOCR:ImageRecognitionInterface
    {
        [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);


        /// <summary>
        /// 识别图像
        /// </summary>
        /// <param name="imgPath"></param>
        /// <returns></returns>
        public string Recognize(string imgPath)
        {
            try
            {
                int startX = 0, startY = 0;
                Image image = Image.FromFile(imgPath);
                return Marshal.PtrToStringAnsi(OCRpart(imgPath, -1, startX, startY, image.Width, image.Height));
            }
            catch (Exception ex)
            {
                Console.WriteLine("识别图像错误:"+ex.Message);
            }
            return "";
        }
    }
}

测试效果

这里通过解析中英文能力来测试

英文识别

中文识别

可见,效果不是很理想,还是要购买其正规渠道的产品才行。

示例和包下载

网上的分比较贵,不建议去下载,因为没什么用,我这里分享一个大家可以做测试使用。

链接:https://pan.baidu.com/s/1Lo3lSnHVvYCfDp-tf9oLnQ

密码:fmai

AspriseOcr也支持Java图像识别:参考http://zxs19861202.iteye.com/blog/1749780

posted @ 2024-09-24 10:38  boonya  阅读(149)  评论(0)    收藏  举报  来源
我有佳人隔窗而居,今有伊人明月之畔。
轻歌柔情冰壶之浣,涓涓清流梦入云端。
美人如娇温雅悠婉,目遇赏阅适而自欣。
百草层叠疏而有致,此情此思怀彼佳人。
念所思之唯心叩之,踽踽彳亍寤寐思之。
行云如风逝而复归,佳人一去莫知可回?
深闺冷瘦独自徘徊,处处明灯影还如只。
推窗见月疑是归人,阑珊灯火托手思忖。
庐居闲客而好品茗,斟茶徐徐漫漫生烟。

我有佳人在水之畔,瓮载渔舟浣纱归还。
明月相照月色还低,浅近芦苇深深如钿。
庐山秋月如美人衣,画堂春阁香气靡靡。
秋意幽笃残粉摇曳,轻轻如诉画中蝴蝶。
泾水潺潺取尔浇园,暮色黄昏如沐佳人。
青丝撩弄长裙翩翩,彩蝶飞舞执子手腕。
香带丝缕缓缓在肩,柔美体肤寸寸爱怜。
如水之殇美玉成欢,我有佳人清新如兰。
伊人在水我在一边,远远相望不可亵玩。