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

编程知识 更新时间:2023-04-04 10:58:37

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

官网地址:http://asprise/

应用场景

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

测试示例

注意:需要下载的DLL分别是AspriseOCR.dll、DevIL.dll、ILU.dll将其放在生成的bin/Debug生成目录下,然后就可以测试了,网上有人说需要 2.0这个是谬传,我用的是 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/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/s/1Lo3lSnHVvYCfDp-tf9oLnQ

密码:fmai

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

更多推荐

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

本文发布于:2023-04-04 10:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/11e5f479276f8722fc06fbebf0aa3efd.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中英文   图像   文字   测试   OCR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 42250文章数
  • 14阅读数
  • 0评论数