示例#1
0
 // ReSharper disable once UnusedMember.Local
 private async Task LoadMem(int channelId, int documentId, OcrVoucher voucher)
 {
     using (var imageFile = System.IO.File.OpenRead(voucher.ImagePath))
     {
         var closureVoucher = voucher;
         closureVoucher.ImageBuffer = new byte[imageFile.Length];
         try
         {
             //read the image file into memory
             await imageFile
                 .ReadAsync(closureVoucher.ImageBuffer, 0, (int)imageFile.Length)
                 .ContinueWith(t =>
                 {
                     //initialize processing in A2IA
                     if (t.IsCompleted && !t.IsFaulted)
                     {
                         a2IaEngine.ScrDefineImage(documentId, configuration.FileType, "MEM", closureVoucher.ImageBuffer);
                         closureVoucher.RequestId = (int)a2IaEngine.ScrOpenRequest(channelId, documentId);
                     }
                     else
                     {
                         throw t.Exception ?? new Exception("Could not process the image.");
                     }
                 });
         }
         catch (Exception ex)
         {
             Log.Error(ex, "An error has ocurred while processing the image for voucher {@voucherId}",
                 closureVoucher.Id);
             if (closureVoucher.RequestId > 0)
             {
                 a2IaEngine.ScrCloseRequest(closureVoucher.RequestId);
             }
         }
     }
 }
示例#2
0
 public void GetIcrChannelResult(OcrVoucher voucher)
 {
     var requestId = 0;
     try
     {
         requestId = GetIcrChannelResult(ChannelId, voucher.RequestId, configuration.ChannelTimeout);
         if (voucher.RequestId == requestId) Functions.GetResult(a2IaEngine, requestId, voucher);
         CloseRequest(requestId);
     }
     catch (Exception ex)
     {
         var errorMessage = a2IaEngine.ScrGetLastError();
         Log.Error(ex, "An error has ocurred while processing the image for voucher {@voucherId} with message {1}", voucher.Id, errorMessage);
         if (requestId > 0) CloseRequest(requestId);
         throw;
     }
 }
示例#3
0
 public void ProcessVoucher(OcrVoucher voucher)
 {
     try
     {
         LoadImage(DocumentId, voucher.ImagePath);
         voucher.RequestId = OpenIcrChannel(ChannelId, DocumentId);
     }
     catch (Exception ex)
     {
         Log.Error(ex, "An error has ocurred while processing the image for voucher {@voucherId}", voucher.Id);
         CloseChannel(ChannelId);
         throw;
     }
 }
示例#4
0
 private string GetBatchId(OcrVoucher voucher)
 {
     return voucher.BatchId;
 }
示例#5
0
        /// <summary>
        /// Populate the OCR results into the metadata associated with the image
        /// </summary>
        /// <param name="a2IaEngine"></param>
        /// <param name="resultId">OCR result Id</param>
        /// <param name="voucher">Metadata of the image to be populated</param>
        public static void GetResult(API a2IaEngine, int resultId, OcrVoucher voucher)
        {
            // A2iA amount recognition
            if (a2IaEngine.GetStringProperty(resultId, Constants.EngineFields.Amount) == Constants.Enabled)
            {
                switch (voucher.VoucherType)
                {
                    case VoucherType.Credit:
                        voucher.AmountResult.Result = a2IaEngine.GetStringProperty(resultId, string.Concat(Constants.ResultFields.CreditBase, "Amount"));
                        voucher.AmountResult.Score = a2IaEngine.GetStringProperty(resultId, string.Concat(Constants.ResultFields.CreditBase, "Score"));
                        break;
                    default:
                        voucher.AmountResult.Result = a2IaEngine.GetStringProperty(resultId, string.Concat(Constants.ResultFields.CheckBase, "Amount"));
                        voucher.AmountResult.Score = a2IaEngine.GetStringProperty(resultId, string.Concat(Constants.ResultFields.CheckBase, "Score"));
                        break;
                }

                var x1 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.AmountLocationX1]);
                var y1 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.AmountLocationY1]);
                var x2 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.AmountLocationX2]);
                var y2 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.AmountLocationY2]);

                voucher.AmountResult.Location = new Rectangle(x1, y1, x2 - x1, y2 - y1);
            }

            // A2iA codeline recognition
            if (a2IaEngine.GetStringProperty(resultId, Constants.EngineFields.CodeLine) == Constants.Enabled)
            {
                voucher.CodelineResult.Result = a2IaEngine.GetStringProperty(resultId, Constants.ResultFields.CodelineRecognition);
                voucher.CodelineResult.Score = a2IaEngine.GetStringProperty(resultId, Constants.ResultFields.CodelineConfidence);

                var x1 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.CodelineLocationX1]);
                var y1 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.CodelineLocationY1]);
                var x2 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.CodelineLocationX2]);
                var y2 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.CodelineLocationY2]);

                voucher.CodelineResult.Location = new Rectangle(x1, y1, x2 - x1, y2 - y1);
            }

            // A2iA date recognition
            if (a2IaEngine.GetStringProperty(resultId, Constants.EngineFields.Date) == Constants.Enabled)
            {
                var day = (uint)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.DateRecognitionDay];
                var month = (uint)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.DateRecognitionMonth];
                var year = (uint)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.DateRecognitionYear];

                voucher.DateResult.Result = string.Format("{0}/{1}/{2}", day, month, year);
                voucher.DateResult.Score = a2IaEngine.GetStringProperty(resultId, Constants.ResultFields.DateConfidence);

                var x1 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.DateLocationX1]);
                var y1 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.DateLocationY1]);
                var x2 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.DateLocationX2]);
                var y2 = (int)((float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.DateLocationY2]);

                voucher.DateResult.Location = new Rectangle(x1, y1, x2 - x1, y2 - y1);
            }

            // Image Rotation
            voucher.ImageRotation = (int)(float)a2IaEngine.ObjectProperty[resultId, Constants.ResultFields.OrientationCorrection];

            Log.Verbose("v {0} - amt {1} score {2} - micr {3} score {4}", voucher.Id, voucher.AmountResult.Result, voucher.AmountResult.Score, voucher.CodelineResult.Result, voucher.CodelineResult.Score);
        }
示例#6
0
 public Task GetResultAsync(int requestId, int documentId, int tableId, int channelId, OcrVoucher voucher)
 {
     return Task.Run(() =>
     {
         int resultId;
         lock (processingLock)
         {
             resultId = GetIcrChannelResult(channelId, requestId, 3000);
         }
         if (resultId == requestId) Functions.GetResult(a2IaEngine, resultId, voucher);
         //ReleaseResources(requestId, documentId, tableId, channelId);
         a2IaEngine.ScrCloseRequest(requestId);
     });
 }
示例#7
0
        private string SetVoucherConfiguration(OcrVoucher voucher)
        {
            string documentTableFilename;

            switch (voucher.VoucherType)
            {
                case VoucherType.Credit:
                    documentTableFilename = configuration.CreditTablePath;
                    break;
                default:
                    documentTableFilename = configuration.DebitTablePath;
                    break;
            }

            return documentTableFilename;
        }