Read Photo
This code example demonstrates how to use the IronTesseract OCR engine to extract text and analyze specific regions from a photo.
using IronOcr;
using IronSoftware.Drawing;
using System;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPhoto = new OcrInput();
inputPhoto.LoadImageFrame("ocr.tiff", 0);
// Read photo
OcrPhotoResult result = ocr.ReadPhoto(inputPhoto);
// Index number refer to region order in the page
int number = result.TextRegions[0].PageNumber;
// Extract the text in the first region
string textinregion = result.TextRegions[0].TextInRegion;
//Extract the co-ordinates of the first text region
Rectangle region = result.TextRegions[0].Region;
var output = $"Text in First Region: {textinregion}\n"
+ $"Text Region:\n"
+ $"Starting X: {region.X}\n"
+ $"Starting Y: {region.Y}\n"
+ $"Region Width: {region.Width}\n"
+ $"Region Height: {region.Height}\n"
+ $"Result Confidence: {result.Confidence}\n\n"
+ $"Full Scnned Photo Text: {result.Text}";
Console.WriteLine(output);Imports Microsoft.VisualBasic
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputPhoto = New OcrInput()
inputPhoto.LoadImageFrame("ocr.tiff", 0)
' Read photo
Dim result As OcrPhotoResult = ocr.ReadPhoto(inputPhoto)
' Index number refer to region order in the page
Dim number As Integer = result.TextRegions(0).PageNumber
' Extract the text in the first region
Dim textinregion As String = result.TextRegions(0).TextInRegion
'Extract the co-ordinates of the first text region
Dim region As Rectangle = result.TextRegions(0).Region
Dim output = $"Text in First Region: {textinregion}" & vbLf & $"Text Region:" & vbLf & $"Starting X: {region.X}" & vbLf & $"Starting Y: {region.Y}" & vbLf & $"Region Width: {region.Width}" & vbLf & $"Region Height: {region.Height}" & vbLf & $"Result Confidence: {result.Confidence}" & vbLf & vbLf & $"Full Scnned Photo Text: {result.Text}"
Console.WriteLine(output)Install-Package IronOcr
This code example demonstrates how to use the IronTesseract OCR engine to extract text and analyze specific regions from a photo.