Exemplo n.º 1
0
        public Task <IRecognitionResults> ExecuteAsync()
        {
            using var document = _pdfDocumentFactory.Open(_pdfFile.Path);
            if (document.ContainsText())
            {
                return(Task.FromResult(document.ExtractText()));
            }

            var storedImages = ExtractImages(document);
            var pixes        = storedImages.SelectMany(x => _pixFactory.Create(x.Path));

            var results = new RecognitionResults();
            var options = new ParallelOptions {
                MaxDegreeOfParallelism = 10
            };

            Parallel.ForEach(pixes, options, pix =>
            {
                IPix preprocessedPix;
                using (pix) preprocessedPix = Preprocess(pix);

                using (preprocessedPix)
                {
                    using var engine      = _engineFactory.Create();
                    var result            = engine.Process(preprocessedPix);
                    var recognitionResult = new RecognitionResult(result);
                    results.BlockingAdd(recognitionResult);
                }
            });

            return(Task.FromResult((IRecognitionResults)results));
        }
        public Task <IRecognitionResults> ExecuteAsync()
        {
            // ToDo: preserve image order
            // ToDo: make async
            var pixes = _pixFactory.Create(_imageFile.Path);

            var results = new RecognitionResults();
            var options = new ParallelOptions {
                MaxDegreeOfParallelism = 10
            };

            Parallel.ForEach(pixes, options, pix =>
            {
                IPix preprocessedPix;
                using (pix) preprocessedPix = Preprocess(pix);

                using (preprocessedPix)
                {
                    using var engine      = _engineFactory.Create();
                    var result            = engine.Process(preprocessedPix);
                    var recognitionResult = new RecognitionResult(result);
                    results.BlockingAdd(recognitionResult);
                }
            });

            return(Task.FromResult <IRecognitionResults>(results));
        }