关键词搜索

源码搜索 ×
×

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

发布2018-07-25浏览19448次

详情内容

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方式导入。

定义接口:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace OCR
  7. {
  8. interface ImageRecognitionInterface
  9. {
  10. /// <summary>
  11. /// 识别图像
  12. /// </summary>
  13. /// <param name="imgPath"></param>
  14. /// <returns></returns>
  15. string Recognize(string imgPath);
  16. }
  17. }

编写工具类和实现:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OCR.ImageRecognition
  9. {
  10. /// <summary>
  11. /// AspriseOCR
  12. /// </summary>
  13. /// DLL包引用:AspriseOCR.dll、DevIL.dll、ILU.dll
  14. /// 下载地址:http://asprise.com/product/ocr/download.php?lang=csharp
  15. public class AspriseOCR:ImageRecognitionInterface
  16. {
  17. [DllImport("AspriseOCR.dll", EntryPoint = "OCR", CallingConvention = CallingConvention.Cdecl)]
  18. public static extern IntPtr OCR(string file, int type);
  19. [DllImport("AspriseOCR.dll", EntryPoint = "OCRpart", CallingConvention = CallingConvention.Cdecl)]
  20. static extern IntPtr OCRpart(string file, int type, int startX, int startY, int width, int height);
  21. [DllImport("AspriseOCR.dll", EntryPoint = "OCRBarCodes", CallingConvention = CallingConvention.Cdecl)]
  22. static extern IntPtr OCRBarCodes(string file, int type);
  23. [DllImport("AspriseOCR.dll", EntryPoint = "OCRpartBarCodes", CallingConvention = CallingConvention.Cdecl)]
  24. static extern IntPtr OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height);
  25. /// <summary>
  26. /// 识别图像
  27. /// </summary>
  28. /// <param name="imgPath"></param>
  29. /// <returns></returns>
  30. public string Recognize(string imgPath)
  31. {
  32. try
  33. {
  34. int startX = 0, startY = 0;
  35. Image image = Image.FromFile(imgPath);
  36. return Marshal.PtrToStringAnsi(OCRpart(imgPath, -1, startX, startY, image.Width, image.Height));
  37. }
  38. catch (Exception ex)
  39. {
  40. Console.WriteLine("识别图像错误:"+ex.Message);
  41. }
  42. return "";
  43. }
  44. }
  45. }

测试效果

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

英文识别

中文识别

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

示例和包下载

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

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

密码:fmai

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

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载