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:
publicoverridestringRecognizeText(StreamimageStream,intpageIndex,OcrOptionsoptions){// Create an instance of Aspose OCR APIAsposeOcrapi=newAsposeOcr();// Convert the image stream into the memory streamusing(MemoryStreammemoryStream=GetMemoryStream(imageStream)){// Create an instance of RecognitionSettingsRecognitionSettingssettings=newRecognitionSettings();// Check if the rectangle is setif(options!=null&&options.Rectangle!=null){List<Aspose.Drawing.Rectangle>areas=newList<Aspose.Drawing.Rectangle>();areas.Add(newAspose.Drawing.Rectangle((int)options.Rectangle.Left,(int)options.Rectangle.Top,(int)options.Rectangle.Size.Width,(int)options.Rectangle.Size.Height));// Set recognition areassettings.RecognitionAreas=areas;}// Perform the text recognitionRecognitionResultresult=api.RecognizeImage(memoryStream,settings);// Check if the handler is setif(options!=null&&options.Handler!=null){// Send all recognition warningsoptions.Handler.OnWarnings(pageIndex,result.Warnings);}// Return a recognized textreturnresult.RecognitionText;}}
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:
publicoverrideIList<PageTextArea>RecognizeTextAreas(StreamimageStream,intpageIndex,Data.SizepageSize,OcrOptionsoptions){// Create an instance of Aspose OCR APIAsposeOcrapi=newAsposeOcr();// Convert the image stream into the memory streamusing(MemoryStreammemoryStream=GetMemoryStream(imageStream)){// Create recognition settings and set detect areasRecognitionSettingssettings=newRecognitionSettings(detectAreas:true);// Check if the rectangle is setif(options!=null&&options.Rectangle!=null){List<Aspose.Drawing.Rectangle>areas=newList<Aspose.Drawing.Rectangle>();areas.Add(newAspose.Drawing.Rectangle((int)options.Rectangle.Left,(int)options.Rectangle.Top,(int)options.Rectangle.Size.Width,(int)options.Rectangle.Size.Height));// Set recognition areassettings.RecognitionAreas=areas;}// Perform the text recognition RecognitionResultr=api.RecognizeImage(memoryStream,settings);// Check if the handler is setif(options!=null&&options.Handler!=null){// Send all recognition warningsoptions.Handler.OnWarnings(pageIndex,r.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);// Combibe rectangle and text collections to produce PageTextArea collectionreturnr.RecognitionAreasRectangles.Zip(r.RecognitionAreasText,(rect,text)=>new{Rect=rect,Text=text}).Select(x=>newPageTextArea(x.Text,page,newData.Rectangle(x.Rect.Left,x.Rect.Top,x.Rect.Right,x.Rect.Bottom))).ToList();}}
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.