public final class OcrEngine extends Object
Main Aspose.OCR class. Users will use instance of this class most of the time.
OcrEngine ocr = new OcrEngine(); ocr.setImage(ImageStream.fromFile("image.tiff")); ocr.getLanguages().addLanguage(Language.load("english")); FileInputStream resourceStream = new FileInputStream(resourceFileName); ocr.setResource(resourceStream); if (ocr.process()) { System.out.println(ocr.getText()); }
| Constructor and Description |
|---|
OcrEngine()
Initializes a new instance of the
OcrEngine class. |
| Modifier and Type | Method and Description |
|---|---|
void |
addNotifier(INotifier processor)
Adds notifier.
|
void |
clearNotifies()
Clear notifiers list.
|
OCRConfig |
getConfig()
Gets configuration.
|
LanguageContainer |
getLanguages()
Gets container recognition languages.
|
Page[] |
getPages()
Gets recognized text divided to pages.
|
boolean |
getProcessAllPages()
Gets a value indicating whether all frames in image must be processed.
|
IRecognizedText |
getText()
Gets recognized text.
|
boolean |
process()
Runs the recognition process.
|
void |
setConfig(OCRConfig value)
Sets configuration.
|
void |
setImage(IImageStream value)
Sets the picture to recognize the text from.
|
void |
setProcessAllPages(boolean value)
Sets a value indicating whether all frames in image must be processed.
|
void |
setResource(InputStream value)
Sets the resource stream.
|
public OcrEngine()
Initializes a new instance of the OcrEngine class.
public void addNotifier(INotifier processor)
Adds notifier.
Each notifier can send event (recognized word, recognized several characters). You can add many notifiers.
OcrEngine ocr = new OcrEngine(); ocr.setImage(ImageStream.fromFile("image.tiff")); ocr.getLanguages().addLanguage(Language.load("english")); INotifier wordNotifier = Notifier.word(); wordNotifier.addElapsedListener((new NotifierHandler() { public void invoke(Object sender, IRecognizedText recognizedText) { System.out.println("1!" + wordNotifier.getText()); } }); INotifier blockNotifier = Notifier.block(1024); blockNotifier.addElapsedListener((new NotifierHandler() { public void invoke(Object sender, IRecognizedText recognizedText) { System.out.println("2!" + blockNotifier.getText()); } }); * ocr.addNotifier(wordNotifier); ocr.addNotifier(blockNotifier); FileInputStream resourceStream = new FileInputStream(resourceFileName); ocr.setResource(resourceStream); if (ocr.process()) { System.out.println(ocr.getText()); }
processor - The processor to add.public void clearNotifies()
Clear notifiers list.
public OCRConfig getConfig()
Gets configuration.
[C#] OcrEngine ocr = new OcrEngine(); ocr.getConfig().setNeedRotationCorrection(false);
public LanguageContainer getLanguages()
Gets container recognition languages.
Enables user to define a list of languages to use for recognition. You may add several languages here.
This property must be set before recognition or specified as one of arguments during process() call.
Recognition of multiple languages. The text is recognized by words. Each recognized word has a specific language. There is priority of recognition languages. Language that was added earlier to the collection has a higher priority. If the word is identical in several languages, a language that was earlier added to the collection will be selected.
OcrEngine ocr = new OcrEngine(); ocr.setImage(ImageStream.fromFile("image.tiff")); ocr.getLanguages().addLanguage(Language.load("english")); ocr.getLanguages().addLanguage(Language.load("spain")); FileInputStream resourceStream = new FileInputStream(resourceFileName); ocr.setResource(resourceStream); if (ocr.process()) { System.out.println(ocr.getText()); }
public Page[] getPages()
Gets recognized text divided to pages. This is only available after recognition is complete, otherwise exception will be raised.
OcrException - Thrown when use before recognition.public boolean getProcessAllPages()
Gets a value indicating whether all frames in image must be processed.
true if all frames in image must be processed.public IRecognizedText getText()
Gets recognized text. This property is only available after recognition is complete, otherwise exception will be raised.
OcrException - Thrown when use before recognition.public boolean process()
Runs the recognition process.
OcrEngine must be configured before running this method, otherwise exception will be thrown. Once this method is called, you may get recognized text from getText() method. Before calling the method, add at least one language to setLanguages() and set image.
OcrException - Thrown if it instance is not configured.public void setConfig(OCRConfig value)
Sets configuration.
value - the OCR configurationcom.aspose.ms.System.ArgumentNullException - Thrown when value is null.public void setImage(IImageStream value)
Sets the picture to recognize the text from.
This property must be set before recognition or specified as one of arguments during process() call.
value - the picture to recognize the text from.public void setProcessAllPages(boolean value)
Sets a value indicating whether all frames in image must be processed.
value - true if all frames in image must be processed.public void setResource(InputStream value)
Sets the resource stream.
Resource stream must be set before recognition or specified as one of arguments during process() call.
OcrEngine ocr = new OcrEngine(); ocr.setImage(ImageStream.fromFile("image.tiff")); ocr.getLanguages().addLanguage(Language.load("english")); FileInputStream resourceStream = new FileInputStream(resourceFileName); ocr.setResource(resourceStream); if (ocr.process()) { System.out.println(ocr.getText()); }
value - the resource stream.Copyright © 2014. All rights reserved.