A zero-based index of the page in the document (in the case when the image represents the document page).
options
Is used to define a rectangular area which restricts the area of the image and OcrEventHandler object to handle warnings while the text recognition.
The following example shows how to implement text recognition by using Aspose.OCR on-premise API:
@OverridepublicStringrecognizeText(java.io.InputStreamimageStream,intpageIndex,OcrOptionsoptions){try{// Create an instance of Aspose OCR API
com.aspose.ocr.AsposeOCRapi=newcom.aspose.ocr.AsposeOCR();// Convert the image stream into the memory stream
java.awt.image.BufferedImageimage=ImageIO.read(imageStream);// Create an instance of RecognitionSettings
com.aspose.ocr.RecognitionSettingssettings=newcom.aspose.ocr.RecognitionSettings();// Check if the rectangle is set
if(options!=null&&options.getRectangle()!=null){ArrayList<java.awt.Rectangle>areas=newArrayList<>();areas.add(newjava.awt.Rectangle((int)options.getRectangle().getLeft(),(int)options.getRectangle().getTop(),(int)options.getRectangle().getSize().getWidth(),(int)options.getRectangle().getSize().getHeight()));// Set recognition areas
settings.setRecognitionAreas(areas);}// Perform the text recognition
com.aspose.ocr.RecognitionResultresult=api.RecognizePage(image,settings);// Check if the handler is set
if(options!=null&&options.getHandler()!=null){// Send all recognition warnings
options.getHandler().onWarnings(pageIndex,result.warnings);}// Return a recognized text
returnresult.recognitionText;}catch(java.lang.Exceptionex){returnnull;}}
A zero-based index of the page in the document (in the case when the image represents the document page).
pageSize
A size of the image (in the case when the image represents the document page - the size of the page).
options
Is used to define a rectangular area which restricts the area of the image and OcrEventHandler object to handle warnings while the text recognition.
The following example shows how to implement text areas recognition by using Aspose.OCR on-premise API:
@Overridepublicjava.lang.Iterable<PageTextArea>recognizeTextAreas(java.io.InputStreamimageStream,intpageIndex,SizepageSize,OcrOptionsoptions){try{// Create an instance of Aspose OCR API
com.aspose.ocr.AsposeOCRapi=newcom.aspose.ocr.AsposeOCR();// Convert the image stream into the memory stream
java.awt.image.BufferedImageimage=ImageIO.read(imageStream);// Create an instance of RecognitionSettings
com.aspose.ocr.RecognitionSettingssettings=newcom.aspose.ocr.RecognitionSettings();settings.setDetectAreas(true);// Check if the rectangle is set
if(options!=null&&options.getRectangle()!=null){ArrayList<java.awt.Rectangle>areas=newArrayList<>();areas.add(newjava.awt.Rectangle((int)options.getRectangle().getLeft(),(int)options.getRectangle().getTop(),(int)options.getRectangle().getSize().getWidth(),(int)options.getRectangle().getSize().getHeight()));// Set recognition areas
settings.setRecognitionAreas(areas);}// Perform the text recognition
com.aspose.ocr.RecognitionResultresult=api.RecognizePage(image,settings);// Check if the handler is set
if(options!=null&&options.getHandler()!=null){// Send all recognition warnings
options.getHandler().onWarnings(pageIndex,result.warnings);}// Create a page object. The pageIndex parameter represents the page index of the document; for images it's always zero.
Pagepage=newPage(pageIndex,pageSize);// Combine rectangle and text collections to produce PageTextArea collection
ArrayList<PageTextArea>areas=newArrayList<>();for(inti=0;i<result.recognitionAreasRectangles.size();i++){java.awt.Rectanglerect=result.recognitionAreasRectangles.get(i);Stringtext=result.recognitionText;areas.add(newPageTextArea(text,page,newRectangle(newPoint(rect.getX(),rect.getY()),newSize(rect.getWidth(),rect.getHeight()))));}returnareas;}catch(java.lang.Exceptionex){returnnull;}}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.