Formula recognition

Aspose.OCR for .NET now provides a dedicated API for detecting and recognizing mathematical formulas in images, scanned documents, screenshots, or photos. To extract formula text, simply call the universal Aspose.OCR.AsposeOcr.RecognizeFormula method.

This method accepts an OcrInput object and optional recognition settings. Internally, formula detection uses the DetectAreasMode.FORMULA mode to locate mathematical expressions before recognition.

Recognition results are returned as a list of Aspose.OCR.RecognitionResult objects. Each result contains extracted formula text, detected regions, and allows exporting to various formats.

DetectAreasMode.FORMULA

Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
// Add images to OcrInput object
Aspose.OCR.OcrInput input = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage);
input.Add("source1.png");
input.Add("source2.jpg");
// Configure recognition settings for formulas
Aspose.OCR.RecognitionSettings settings = new Aspose.OCR.RecognitionSettings();
settings.DetectAreasMode = Aspose.OCR.DetectAreasMode.FORMULA;
// Recognize formulas on the image
Aspose.OCR.OcrOutput results = recognitionEngine.Recognize(input, recognitionSettings);
foreach(Aspose.OCR.RecognitionResult result in results)
{
	Console.WriteLine(result.RecognitionText);
}

RecognizeFormula(OcrInput images, bool detectAreas = true)

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

// Recognize formulas with areas detection
Aspose.OCR.OcrOutput results = recognitionEngine.RecognizeFormula(input, true);
// Parameter bool detectAreas - if set to true, automatically detects and isolates formula regions before performing recognition. If false, processes the entire image as a formula.

foreach(Aspose.OCR.RecognitionResult result in results)
{
	Console.WriteLine(result.RecognitionText);
}

Live demo

recognitionEngine.RecognizeFormula(input, true)
Formula with text Formulas regions
x_{c} ( t )=\\sin\left( 2 \\pi( 1 0 0 ) t \right)
T=1 / 4 0 0
x [ n ]
x [ n ]
x [ n ]=\\cos\left( {\\frac{\\pi} {4}} n \right) , \\qquad-\\infty< n < \\infty.

Live demo

recognitionEngine.RecognizeFormula(input, false)
Formula without text
x [ n ]=\\cos\left( \\frac{\\pi} {4} n \right) . \\qquad-\\infty< n < \\infty.