public async Task <(IEnumerable <ISpatialText> Texts, string Language)> Ocr(Stream image, string?inputLanguage = null) { if (!_configuration.Cache) { return(await _decorated.Ocr(image, inputLanguage)); } var cached = GetCached(); if (cached != null) { return(cached, "en"); } var newResult = (await _decorated.Ocr(image, inputLanguage)); Cache(newResult.Texts); return(newResult); }
public async Task <(IEnumerable <ISpatialText> Texts, string Language)> Ocr(Stream image, string?inputLanguage = null) { const int unitUsage = 1; await VerifyQuotaSpace(unitUsage); await UseQuota(unitUsage); var result = await _ocrImplementation.Ocr(image, inputLanguage); return(result); }
public async Task <(IEnumerable <ISpatialText> Texts, string Language)> Ocr(Stream image, string?inputLanguage = null) { var googleOcrResult = await _decorated.Ocr(image, inputLanguage); var consolidated = (_spatialTextConsolidator.Consolidate(googleOcrResult.Texts)).ToList(); foreach (var spatialText in consolidated) { _logger.LogInformation(spatialText.Text); } return(consolidated, googleOcrResult.Language); }
public async Task <ConsolidatedMachineAddressableOcr> MachineOcrImage(ImageReference reference, Stream content) { var(texts, language) = await _ocr.Ocr(content); var spatialTexts = texts as ISpatialText[] ?? texts.ToArray(); var rawMachineOcr = new RawMachineOcr(language, MachineOcrProvider.Google, DateTime.UtcNow, spatialTexts) { ForImage = reference.Id }; rawMachineOcr = await _machineOcrRepository.Save(rawMachineOcr); var consolidated = CreateAddressableMachineOcr(rawMachineOcr); return(await _machineOcrRepository.Save(consolidated)); }
private async Task <IList <ISpatialText> > OcrScreenInternal() { ShowOverlay(); var captureLocation = _ocrTranslateOverlayConfiguration.CaptureArea; _internalOverlay.ClearAll(); _internalOverlay.Add(new SpatialText("Will capture here", captureLocation)); await Task.Delay(TimeSpan.FromSeconds(1)); _log.LogInformation("Hiding overlay for ocr"); HideOverlay(); await Task.Delay(TimeSpan.FromSeconds(0.2)); _log.LogInformation("Capturing screen"); var(stream, bitmap) = _screenImageProvider.Get(captureLocation); using (stream) { using (bitmap) { if (_ocrTranslateOverlayConfiguration.DebugCapturedImage) { await DebugImage(stream, bitmap); } _log.LogInformation("Ocr-ing the image"); var recognizedTextboxes = await _ocr.Ocr(stream, _ocrTranslateOverlayConfiguration.SourceLanguage); return(recognizedTextboxes.Texts.ToList()); } } }