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:
- Install the Aspose.OCR package via NuGet or from a downloaded distributive. See Installation for detailed instructions.
- 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 area | Supported options |
|---|---|
| Licensed method | Recognize |
| Input type | InputType.SingleImage |
| Area detection modes | DetectAreasMode.CURVED_TEXT, DetectAreasMode.LEAN, DetectAreasMode.UNIVERSAL |
| Preprocessing filters | PreprocessingFilter.AutoSkew(), Binarize(), Resize(), Dilate(), Invert(), Rotate(), Scale(), ToGrayscale(), Threshold(), Median() |
| Language selection | RecognitionSettings.Language supports 154 Language enum values, including Auto, Multilanguage, and Universal |
| Common public recognition settings | RecognizeSingleLine, UpscaleSmallFont, LinesFiltration, ThreadsCount, AutomaticColorInversion |
| Plugin license restriction | Custom 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
OcrInputwith repeatedinput.Add(...)calls to recognize them as a batch. - OCR processing uses internal multithreading. Configure the number of worker threads with
RecognitionSettings.ThreadsCount; use1for low-powered machines or increase the value on multi-core systems to speed up recognition. - Subscribe to the
AsposeOcr.OcrProgressevent 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(), orMedian()before recognition. - For mobile photos, ensure proper lighting and contrasting backgrounds.
- Tune
ThreadsCountfor 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.