Пример #1
0
        public async Task <IRecognitionResults> RecognizeAsync(IRecognitionConfiguration config, bool runParallel = true)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var type = await _recognizer.GetFileTypeAsync(config.File.DataStream);

            if (type == ImageFileTypes.Unrecognized)
            {
                throw new InvalidOperationException("Image file type not recognized.");
            }

            var tesseractFactory = _tesseractFactory.CreateFactory(config.Engine.TessData, config.Engine.Language, (EngineMode)config.Engine.EngineMode);
            var preprocessors    = config.Preprocessors.Select(x => _preprocessorFactory.Create(x)).ToArray();

            using var storedFile = await _storage.StoreAsync(config.File);

            if (config.File.DisposeStream)
            {
                config.File.DataStream.Dispose();
            }

            var job = _jobFactory.Create(type, storedFile, tesseractFactory, preprocessors);

            if (runParallel)
            {
                return(await _jobQueue.EnqueueAsync(job));
            }
            return(await job.ExecuteAsync());
        }
Пример #2
0
        private IStoredImageFile ExportJpegImage(PdfDictionary image)
        {
            var bytes = image.Stream.Value;

            return(_storage.StoreAsync(bytes).Result);
        }