Formula recognition

Aspose.OCR for Java 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.com.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.com.RecognitionResult objects. Each result contains extracted formula text, detected regions, and allows exporting to various formats.

DetectAreasMode.FORMULA

The following code example shows how to extract text from table and get rows and columns structure:

com.aspose.ocr.AsposeOCR recognitionEngine = new com.aspose.ocr.AsposeOCR();
// Add images to OcrInput object
com.aspose.ocr.OcrInput input = new com.aspose.ocr.OcrInput(InputType.SingleImage);
input.add("source1.png");
input.add("source2.jpg");
// Configure recognition settings for formulas
com.aspose.ocr.RecognitionSettings settings = new com.aspose.ocr.RecognitionSettings();
settings.setDetectAreasMode(DetectAreasMode.FORMULA);
// Recognize formulas on the image
com.aspose.ocr.OcrOutput results = recognitionEngine.Recognize(input, recognitionSettings);

results.forEach((result) -> {
	System.out.println(result.recognition_text);
});

RecognizeFormula(OcrInput images, bool detectAreas = true)

com.aspose.ocr.AsposeOCR recognitionEngine = new com.aspose.ocr.AsposeOCR();
// Add images to OcrInput object
com.aspose.ocr.OcrInput input = new com.aspose.ocr.OcrInput(InputType.SingleImage);
input.add("source1.png");
input.add("source2.jpg");

// Recognize formulas with areas detection
com.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.

results.forEach((result) -> {
	System.out.println(result.recognition_text);
});

Live demo

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

Live demo

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