Ejemplo n.º 1
0
        public async Task Install_Uninstall_Tesseract()
        {
            await installer.Install();

            Assert.IsTrue(File.Exists(installer.TesseractExePath));
            await installer.Install(); //It should work even if the program is already installed

            Assert.IsTrue(File.Exists(installer.TesseractExePath));

            installer.UninstallTesseract();
            Assert.IsFalse(Directory.Exists(installer.TesseractInstallDir));
            installer.UninstallTesseract();//It should work even if the program is already uninstalled
            Assert.IsFalse(Directory.Exists(installer.TesseractInstallDir));
        }
        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);
        }