Aspose.OCR Photo to Text for .NET

Aspose.OCR Photo to Text for .NET extracts text from individual raster images or batches of images captured by cameras or smartphones. The licensed plugin scope is defined by the supported OCR methods, input type, area detection modes, preprocessing filters, and recognition settings below.

Installation and Setup

Getting started is simple:

  1. Install the Aspose.OCR package via NuGet or from a downloaded distributive. See Installation for detailed instructions.
  2. Configure metered licensing at startup to unlock full functionality. Refer to Metered Licensing for setup steps.

Supported Plugin Options

The plugin license enables these API capabilities:

API areaSupported options
Licensed methodRecognize
Input typeInputType.SingleImage
Area detection modesDetectAreasMode.CURVED_TEXT, DetectAreasMode.LEAN, DetectAreasMode.UNIVERSAL
Preprocessing filtersPreprocessingFilter.AutoSkew(), Binarize(), Resize(), Dilate(), Invert(), Rotate(), Scale(), ToGrayscale(), Threshold(), Median()
Language selectionRecognitionSettings.Language supports 154 Language enum values, including Auto, Multilanguage, and Universal
Common public recognition settingsRecognizeSingleLine, UpscaleSmallFont, LinesFiltration, ThreadsCount, AutomaticColorInversion
Plugin license restrictionCustom RecognitionAreas are not included; keep RecognitionAreas empty

Skew correction is configured through PreprocessingFilter.AutoSkew(), not through RecognitionSettings. Manual rotation and other image cleanup steps can be configured with preprocessing filters such as Rotate(), Binarize(), ToGrayscale(), Threshold(), and Median(). Auto denoising, auto dewarping, contrast correction, auto contrast, DetectAreasMode: TABLE, MULTICOLUMN, FORMULA values are not listed for this plugin in the license service.

Supported Workflow

Use OcrInput with InputType.SingleImage, add photo files, configure RecognitionSettings, and call Recognize. Add multiple photos with repeated input.Add(...) calls to recognize a batch in one request. For curved or perspective-distorted text, use DetectAreasMode.CURVED_TEXT; for simple images, use DetectAreasMode.LEAN or DetectAreasMode.UNIVERSAL.

Example: Extracting Text from Photos

Aspose.OCR.Metered metered = new Aspose.OCR.Metered();
metered.SetMeteredKey("PublicKey", "PrivateKey");

// Initialize OCR engine
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();

// Add images to input
Aspose.OCR.OcrInput input = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage);
input.Add("source1.png");
input.Add("source2.jpg");

// Configure recognition settings for photo detection
Aspose.OCR.RecognitionSettings recognitionSettings = new Aspose.OCR.RecognitionSettings();
recognitionSettings.DetectAreasMode = Aspose.OCR.DetectAreasMode.CURVED_TEXT;

// Perform recognition
Aspose.OCR.OcrOutput results = recognitionEngine.Recognize(input, recognitionSettings);
foreach (Aspose.OCR.RecognitionResult result in results)
{
    Console.WriteLine(result.RecognitionText);
}

// Save results
results[0].Save("result.txt", Aspose.OCR.SaveFormat.Text);
results.Save("result.pdf", Aspose.OCR.SaveFormat.Pdf);
results.Save("result.json", Aspose.OCR.SaveFormat.Json);

Output Formats and Saving Results

Use RecognitionResult.Save(...) to save a single recognized photo, OcrOutput.Save(...) to save the whole recognition batch, or AsposeOcr.SaveMultipageDocument(...) to combine several results into one output document.

Supported SaveFormat values are Text, Docx, Pdf, PdfNoImg, Xlsx, Xml, Json, HTML, EPUB, RTF, HOCR, Md, and Csv. You can also read recognized text, bounding boxes, line data, and confidence values directly from the result objects before deciding whether to save the output.

Batch Processing and Execution Control

  • Add multiple image files to OcrInput with repeated input.Add(...) calls to recognize them as a batch.
  • OCR processing uses internal multithreading. Configure the number of worker threads with RecognitionSettings.ThreadsCount; use 1 for low-powered machines or increase the value on multi-core systems to speed up recognition.
  • Subscribe to the AsposeOcr.OcrProgress event to track recognition progress.
  • Use the Recognize(input, settings, cancellationToken) overload when a long-running recognition operation must support cancellation.

Tips and Best Practices

  • Pre-select or crop regions of interest to minimize processing time.
  • For low-quality photos, apply supported preprocessing filters such as PreprocessingFilter.AutoSkew(), Rotate(), Binarize(), Threshold(), ToGrayscale(), or Median() before recognition.
  • For mobile photos, ensure proper lighting and contrasting backgrounds.
  • Tune ThreadsCount for the target machine: use a single thread when resources are limited, or multiple threads to process batches faster.

Frequently Asked Questions

Is specifying a language necessary? By default, the plugin auto-detects many languages. However, explicitly setting the language improves accuracy for scripts like Cyrillic, Chinese, or Hindi.

What formats are supported? Use InputType.SingleImage, which supports common image formats such as GIF, PNG, JPEG, BMP, TIFF, and JFIF.

How can I achieve the best results? Use high-quality images from scanners or modern cameras. Built-in filters enhance image quality before recognition.

 English