public string GetTextIronOCR(string path) { if (IronOcr.License.IsValidLicense(LicenseKey)) { IronOcr.License.LicenseKey = LicenseKey; } else { return(""); } var advancedOCR = new IronOcr.AdvancedOcr() { CleanBackgroundNoise = false, ColorDepth = 4, ColorSpace = IronOcr.AdvancedOcr.OcrColorSpace.GrayScale, EnhanceContrast = true, DetectWhiteTextOnDarkBackgrounds = false, RotateAndStraighten = false, Language = IronOcr.Languages.English.OcrLanguagePack, EnhanceResolution = false, InputImageType = IronOcr.AdvancedOcr.InputTypes.Document, ReadBarCodes = true, Strategy = IronOcr.AdvancedOcr.OcrStrategy.Advanced }; IronOcr.AutoOcr _OCR = new IronOcr.AutoOcr(); IronOcr.OcrResult ocrResult = advancedOCR.ReadPdf(path, 2); var Pages = ocrResult.Pages; var Barcodes = ocrResult.Barcodes; var FullPdfText = ocrResult.Text; return(FullPdfText); }
/// <summary> /// Compares an IronOcr.OcrResult against a Text File with the true text of a document. /// /// Copyright 2018 https://ironsoftware.com/csharp/ocr/ /// </summary> /// <param name="Result">the IronOCR OcrResult</param> /// <param name="ComparisonFilePath">A text file path which contains the exact text of the original document.</param> /// <returns></returns> public static decimal Compare(IronOcr.OcrResult Result, string ComparisonFilePath) { string OCRText = Result.Text; string TrueText = File.ReadAllText(ComparisonFilePath); OCRText = NormalizeWhiteSpace(OCRText); TrueText = NormalizeWhiteSpace(TrueText); OCRText = NormalizePunctuation(OCRText); TrueText = NormalizePunctuation(TrueText); int StringDistance = LevenshteinStringDistance(OCRText, TrueText); decimal PercentageMatch = 100M * ((decimal)TrueText.Length - (decimal)StringDistance) / (decimal)TrueText.Length; decimal RoundedResult = Math.Round(PercentageMatch, 1); Console.WriteLine(""); Console.WriteLine("OCR Accuracy was {0} %", RoundedResult); Console.WriteLine(""); return(RoundedResult); }