/// <summary> /// Retrieve text from the given OCR results object. /// </summary> /// <param name="results">The OCR results.</param> /// <returns>Return the text.</returns> private void ShowRetrieveText(OcrResults results) { StringBuilder stringBuilder = new StringBuilder(); if (results != null && results.Regions != null) { stringBuilder.Append("Text: "); stringBuilder.AppendLine(); foreach (var item in results.Regions) { foreach (var line in item.Lines) { foreach (var word in line.Words) { stringBuilder.Append(word.Text); stringBuilder.Append(" "); } stringBuilder.AppendLine(); } stringBuilder.AppendLine(); } } Console.ForegroundColor = ConsoleColor.Green; Console.Write(stringBuilder.ToString()); Console.ResetColor(); }
/// <summary> /// Log text from the given OCR results object. /// </summary> /// <param name="results">The OCR results.</param> protected void LogOcrResults(OcrResults results) { StringBuilder stringBuilder = new StringBuilder(); if (results != null && results.Regions != null) { stringBuilder.Append("Text: "); stringBuilder.AppendLine(); foreach (var item in results.Regions) { foreach (var line in item.Lines) { foreach (var word in line.Words) { stringBuilder.Append(word.Text); stringBuilder.Append(" "); } stringBuilder.AppendLine(); } stringBuilder.AppendLine(); } } Log(stringBuilder.ToString()); }
private async void detectButton_Click(object sender, RoutedEventArgs e) { var pivotItem = Pivot.SelectedItem as PivotItem; if (pivotItem != null) { if (pivotItem == AnalysisItem) { if (_selectedImageFile != null) { using (var stream = await _selectedImageFile.OpenStreamForReadAsync()) { var result = await _serviceClient.AnalyzeImageAsync(stream); if (result != null) { AnalysisResult = result; AnalysisListBox.ItemsSource = result.Categories; } } } } if (pivotItem == OcrItem) { if (_selectedImageFile != null) { using (var stream = await _selectedImageFile.OpenStreamForReadAsync()) { var result = await _serviceClient.RecognizeTextAsync(stream); OcrResult = result; foreach (var region in OcrResult.Regions) { foreach (var line in region.Lines) { foreach (var word in line.Words) { OcrResultsTextBox.Text += word.Text; OcrResultsTextBox.Text += ' '; } } } } } } } }
public ObservableCollection<Face> OcrGetFramesRectanglesForRecognizedText(OcrResults ocrResults, string selectedFile) { var frames = new ObservableCollection<Face>(); var imageInfo = GetImageInfoForRendering(selectedFile); foreach (var region in ocrResults.Regions) { var face = new Face(); face = CalculateTextRectangleForRendering(face, MaxImageSize, imageInfo, region.Rectangle.Left, region.Rectangle.Top, region.Rectangle.Height, region.Rectangle.Width); face.ScoredEmotion = $"lines {region.Lines.Length}"; frames.Add(face); } return frames; }
public string OcrRecognizeTextAsString(OcrResults ocrResult) { var result = $@"Language: {ocrResult.Language} Orientation: {ocrResult.Orientation} Text Angle: {ocrResult.TextAngle} "; foreach (var region in ocrResult.Regions) { result += $@"Region BoundingBox: {region.BoundingBox} Rectangle: Left {region.Rectangle.Left}, Top {region.Rectangle.Top}, Height {region.Rectangle.Height}, Width {region.Rectangle.Width} Lines "; foreach (var line in region.Lines) { foreach (var word in line.Words) { result += $@"{word.Text} "; } result += $@" "; } } return result; }
static IEnumerable<string> ToLines(OcrResults ocr) => ocr.Regions .SelectMany(r => r.Lines) .Select(ToText);