Richard.Ma 发表于 2017-7-17 09:41:21

如何使用MICR检测和OCR自动检测和识别检查

附加的是使用Leadtools图像处理和OCR SDK的VS2017 C#项目,以便自动执行检查过程。 正在做大部分工作的图像处理命令是MICRCodeDetectionCommand:
https://www.leadtools.com/help/leadtools/v19m/dh/po/micrcodedetectioncommand.html

以下是实现此目的的相关方法:
private string DetectandRecognizeMICR(string fileName)
      {
         try
         {
            string micr = "";
            //Initialize the codecs class and load the image
            using (RasterCodecs codecs = new RasterCodecs())
            {
               using (RasterImage img = codecs.Load(fileName))
               {
                  //prepare the MICR detector command and run it
                  MICRCodeDetectionCommand micrDetector = new MICRCodeDetectionCommand();
                  micrDetector.SearchingZone = new LeadRect(0, 0, img.Width, img.Height);
                  micrDetector.Run(img);

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

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

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

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

                     //return the MICR text
                     micr = ocrPage.GetText(-1);
                  }
               }
            }
            return micr;
         }
         catch (Exception ex)
         {
            return ex.Message;
         }
      }请注意,如果您希望将其作为自动化过程,您不应该处理OCREngine,并且应该仅在启动应用程序/线程时启动它,然后在应用程序/线程停止后将其关闭/处理。

页: [1]
查看完整版本: 如何使用MICR检测和OCR自动检测和识别检查