public static List <IGenericOcrRunner> GetStandardOcrs(IOcrCache ocrCache, StandardOcrSettings standardOcrSettings) { List <IGenericOcrRunner> genericOcrRunners = new List <IGenericOcrRunner>(); if (standardOcrSettings.AwsOcrSettings != null) { var awsSettings = standardOcrSettings.AwsOcrSettings; genericOcrRunners.Add(new AwsOcrService(ocrCache, awsSettings.AccessKey, awsSettings.SecretKey)); } if (standardOcrSettings.AzureOcrSettings != null) { var azureSettings = standardOcrSettings.AzureOcrSettings; genericOcrRunners.Add(new AzureOcrExecutor(ocrCache, azureSettings.SubscriptionKey, azureSettings.Endpoint)); } if (standardOcrSettings.GoogleOcrSettings != null) { var googleSettings = standardOcrSettings.GoogleOcrSettings; genericOcrRunners.Add(new GoogleOcrService(ocrCache, googleSettings.ApiToken)); } if (standardOcrSettings.TesseractOcrSettings != null) { var tesseractSettings = standardOcrSettings.TesseractOcrSettings; genericOcrRunners.Add(new TesseractService(ocrCache, tesseractSettings.TesseractDir, tesseractSettings.DataDir)); } if (standardOcrSettings.WindowsOcrSettings != null) { genericOcrRunners.Add(new WindowsOcrExecutor(ocrCache)); } return(genericOcrRunners); }
/// <summary> /// Initializes a new instance of the <see cref="TesseractService"/> class. /// </summary> /// <param name="tesseractDir">The path for the Tesseract4 installation folder (C:\Program Files\Tesseract-OCR).</param> /// <param name="dataDir">The data with the trained models (tessdata). Download the models from https://github.com/tesseract-ocr/tessdata_fast</param> public TesseractService(IOcrCache ocrCache, string tesseractDir = @"C:\Program Files\Tesseract-OCR", string dataDir = null) : base(ocrCache) { // Tesseract configs. _tesseractExePath = Path.Combine(tesseractDir, "tesseract.exe"); if (String.IsNullOrEmpty(dataDir)) { dataDir = Path.Combine(tesseractDir, "tessdata"); } Environment.SetEnvironmentVariable("TESSDATA_PREFIX", dataDir); }
public WindowsOcrExecutor(IOcrCache ocrCache) : base(ocrCache) { var taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1); factory = new TaskFactory(taskScheduler); powershell = PowerShell.Create(); string psScript = GetResourceText("Get-Text-Win-OCR.ps1"); powershell.AddScript(psScript, false); powershell.Invoke(); this.ocrCache = ocrCache; }
public static async Task <List <IGenericOcrRunner> > GetStandardOcrs(IOcrCache ocrCache, StandardOcrSettings standardOcrSettings, IImageCompressor imageCompressor) { List <IGenericOcrRunner> genericOcrRunners = new List <IGenericOcrRunner>(); var ocrParams = new HighLevelOcrServiceParams { OcrCache = ocrCache, ImageCompressor = imageCompressor }; if (standardOcrSettings.AwsOcrSettings != null) { var awsSettings = standardOcrSettings.AwsOcrSettings; genericOcrRunners.Add(new AwsOcrService(awsSettings.AccessKey, awsSettings.SecretKey, awsSettings.Region, ocrParams)); } if (standardOcrSettings.AzureOcrSettings != null) { var azureSettings = standardOcrSettings.AzureOcrSettings; genericOcrRunners.Add(new AzureOcrService(azureSettings.SubscriptionKey, azureSettings.Endpoint, ocrParams)); } if (standardOcrSettings.GoogleOcrSettings != null) { var googleSettings = standardOcrSettings.GoogleOcrSettings; genericOcrRunners.Add(new GoogleOcrService(googleSettings.ApiToken, ocrParams)); } if (standardOcrSettings.TesseractOcrSettings != null) { var tesseractSettings = standardOcrSettings.TesseractOcrSettings; if (tesseractSettings.ShouldTryToAutomaticallInstall && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var tesseractInstaller = new WindowsTesseractInstaller(tesseractSettings.TesseractExecutable); await tesseractInstaller.Install(); tesseractSettings.Installer = tesseractInstaller; tesseractSettings.TesseractExecutable = tesseractInstaller.TesseractExePath; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { tesseractSettings.TesseractExecutable = "tesseract"; } genericOcrRunners.Add(new TesseractOcrService(tesseractSettings.TesseractExecutable, tesseractSettings.DataDir, ocrParams)); } if (standardOcrSettings.WindowsOcrSettings != null && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { genericOcrRunners.Add(new WindowsOcrService(ocrParams)); } return(genericOcrRunners); }
public GenericOcrRunner(IOcrCache ocrCache) { this.ocrCache = ocrCache; }
public AwsOcrService(IOcrCache ocrCache, string accessKey, string secretKey) : base(ocrCache) { rekognitionClient = new AmazonRekognitionClient(accessKey, secretKey); }
public AzureOcrExecutor(IOcrCache ocrCache, string subscriptionKey, string endpoint) : base(ocrCache) { this.subscriptionKey = subscriptionKey; this.endpoint = endpoint; uriBase = endpoint + "vision/v2.1/ocr"; }
public GoogleOcrService(IOcrCache ocrCache, string apiToken) : base(ocrCache) { this.apiToken = apiToken; }
public StandardMultiOcrRunnerFactory(StandardOcrSettings settings, IOcrCache ocrCache) { this.Settings = settings; this.ocrCache = ocrCache; this.imageCompressor = settings.ImageCompressor; }
public StandardMultiOcrRunnerFactory(StandardOcrSettings settings, IOcrCache ocrCache) { this.settings = settings; this.ocrCache = ocrCache; }