找回密码
 立即注册

QQ登录

只需一步,快速开始

Richard.Ma 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2017-7-17 09:41  /   查看:2757  /  回复:0
附加的是使用Leadtools图像处理和OCR SDK的VS2017 C#项目,以便自动执行检查过程。 正在做大部分工作的图像处理命令是MICRCodeDetectionCommand:
https://www.leadtools.com/help/l ... tectioncommand.html

以下是实现此目的的相关方法:
  1. private string DetectandRecognizeMICR(string fileName)
  2.       {
  3.          try
  4.          {
  5.             string micr = "";
  6.             //Initialize the codecs class and load the image
  7.             using (RasterCodecs codecs = new RasterCodecs())
  8.             {
  9.                using (RasterImage img = codecs.Load(fileName))
  10.                {
  11.                   //prepare the MICR detector command and run it
  12.                   MICRCodeDetectionCommand micrDetector = new MICRCodeDetectionCommand();
  13.                   micrDetector.SearchingZone = new LeadRect(0, 0, img.Width, img.Height);
  14.                   micrDetector.Run(img);

  15.                   //See if there is a MICR detected - if not return
  16.                   if (micrDetector.MICRZone == LeadRect.Empty)
  17.                      return "No MICR detected in this file.";

  18.                   //if there is a MICR zone detected startup OCR
  19.                   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
  20.                   {
  21.                      ocrEngine.Startup(null, null, null, null);

  22.                      //create the OCR Page
  23.                      IOcrPage ocrPage = ocrEngine.CreatePage(img, OcrImageSharingMode.None);

  24.                      //Create the OCR zone for the MICR and add to the Ocr Page and recognize
  25.                      OcrZone micrZone = new OcrZone();
  26.                      micrZone.Bounds = LogicalRectangle.FromRectangle(micrDetector.MICRZone);
  27.                      micrZone.ZoneType = OcrZoneType.Micr;
  28.                      ocrPage.Zones.Add(micrZone);
  29.                      ocrPage.Recognize(null);

  30.                      //return the MICR text
  31.                      micr = ocrPage.GetText(-1);
  32.                   }
  33.                }
  34.             }
  35.             return micr;
  36.          }
  37.          catch (Exception ex)
  38.          {
  39.             return ex.Message;
  40.          }
  41.       }
复制代码
请注意,如果您希望将其作为自动化过程,您不应该处理OCREngine,并且应该仅在启动应用程序/线程时启动它,然后在应用程序/线程停止后将其关闭/处理。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部