com.aspose.ocr

## Class OcrEngine

- java.lang.Object
- - com.aspose.ocr.OcrEngine

-     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 Summary

    Constructors
    Constructor and Description
    `OcrEngine()` Initializes a new instance of the `OcrEngine` class.

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### OcrEngine

          public OcrEngine()

      Initializes a new instance of the `OcrEngine` class.

  - ### Method Detail

    - #### addNotifier

          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());
      >      }

      Parameters:
        `processor` - The processor to add.

    - #### clearNotifies

          public void clearNotifies()

      Clear notifiers list.

    - #### getConfig

          public OCRConfig getConfig()

      Gets configuration.

      >      [C#]
      >      OcrEngine ocr = new OcrEngine();
      >      ocr.getConfig().setNeedRotationCorrection(false);

      Returns:
        the OCR configuration

    - #### getLanguages

          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());
      >      }

      Returns:
        container recognition languages.

    - #### getPages

          public Page[] getPages()

      Gets recognized text divided to pages. This is only available after recognition is complete, otherwise exception will be raised.

      Returns:
        recognized text divided to pages.
      Throws:
        `OcrException` - Thrown when use before recognition.

    - #### getProcessAllPages

          public boolean getProcessAllPages()

      Gets a value indicating whether all frames in image must be processed.

      Returns:
        `true` if all frames in image must be processed.

    - #### getText

          public IRecognizedText getText()

      Gets recognized text. This property is only available after recognition is complete, otherwise exception will be raised.

      Returns:
        the recognized text.
      Throws:
        `OcrException` - Thrown when use before recognition.

    - #### process

          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.

      Returns:
        A value indicating whether text has been recognized successfully.
      Throws:
        `OcrException` - Thrown if it instance is not configured.

    - #### setConfig

          public void setConfig(OCRConfig value)

      Sets configuration.

      Parameters:
        `value` - the OCR configuration
      Throws:
        `com.aspose.ms.System.ArgumentNullException` - Thrown when value is null.

    - #### setImage

          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.

      Parameters:
        `value` - the picture to recognize the text from.

    - #### setProcessAllPages

          public void setProcessAllPages(boolean value)

      Sets a value indicating whether all frames in image must be processed.

      Parameters:
        `value` - `true` if all frames in image must be processed.

    - #### setResource

          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());
      >      }

      Parameters:
        `value` - the resource stream.

Copyright © 2014. All rights reserved.