/// <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, Constants.ResultFields.Amount1); var temp = a2IaEngine.GetStringProperty(resultId, string.Concat(Constants.ResultFields.CreditBase, "Amount")); var temp1 = a2IaEngine.GetStringProperty(resultId, string.Concat(Constants.ResultFields.AltCreditBase, "Amount")); var temp2 = a2IaEngine.GetStringProperty(resultId, string.Concat(Constants.ResultFields.CheckBase, "Amount")); System.Diagnostics.Debug.WriteLine("credit base = {0}, alt credit base = {1} check base = {2}", temp, temp1, temp2); voucher.AmountResult.Score = a2IaEngine.GetStringProperty(resultId, Constants.ResultFields.AmountConfidence1); break; default: voucher.AmountResult.Result = a2IaEngine.GetStringProperty(resultId, Constants.ResultFields.Amount); voucher.AmountResult.Score = a2IaEngine.GetStringProperty(resultId, Constants.ResultFields.AmountConfidence); 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); }
public void GetIcrChannelResult(OcrVoucher voucher) { var requestId = 0; try { requestId = GetIcrChannelResult(_channelId, voucher.RequestId, _channelTimeout); if (voucher.RequestId == requestId) Functions.GetResult(_a2IaEngine, requestId, voucher); //Console.WriteLine("Voucher request {0} being retrieved", requestId); CloseRequest(requestId); } catch (Exception ex) { var errorMessage = _a2IaEngine.ScrGetLastError(); Log.Error(ex, "An error has ocurred getting the results for the image for voucher {@voucherId}, with error {1}", voucher.Id, errorMessage); if (requestId > 0) CloseRequest(requestId); throw; } }
public void ProcessVoucher(OcrVoucher voucher) { try { LoadImage(_documentId, voucher.ImagePath); voucher.RequestId = OpenIcrChannel(_channelId, _documentId); Log.Debug("Voucher Request {0} in progress", voucher.RequestId); } catch (Exception ex) { Log.Error(ex, "An error has ocurred while processing the image for voucher {@voucherId}", voucher.Id); CloseChannel(_channelId); throw; } }
private async Task LoadMem(int channelId, int documentId, OcrVoucher voucher) { using (var imageFile = 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, _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); } } } }