Table recognition

Aspose.OCR for Java now provides a dedicated API for detecting table layout and recognizing table data in images, scanned documents, screenshots, or photos. To extract table text, simply call the universal com.aspose.ocr.AsposeOCR.Recognize method with DetectAreasMode.TABLE settings.

This method accepts an OcrInput object and optional recognition settings.

Recognition results are returned as a list of com.aspose.ocr.AsposeOCR.RecognitionResult objects. Each result contains extracted table data, detected regions, and allows exporting to various formats. Additionally, you can retrieve the table’s row and column structure using the GetTableData() method.

DetectAreasMode.TABLE and GetTableData

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 tables
com.aspose.ocr.RecognitionSettings settings = new com.aspose.ocr.RecognitionSettings();
settings.setDetectAreasMode(DetectAreasMode.TABLE);
// Recognize tables on the image
com.aspose.ocr.OcrOutput results = recognitionEngine.Recognize(input, recognitionSettings);
com.aspose.ocr.models.OCRTable table = results.GetTableData();

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