Package org.opencv.dnn

## Class TextRecognitionModel

- java.lang.Object
- - org.opencv.dnn.Model
  - - org.opencv.dnn.TextRecognitionModel

-     public class TextRecognitionModel
      extends Model

  This class represents high-level API for text recognition networks. TextRecognitionModel allows to set params for preprocessing input image. TextRecognitionModel creates net from file with trained weights and config, sets preprocessing input, runs forward pass and return recognition result. For TextRecognitionModel, CRNN-CTC is supported.

- - ### Field Summary

    - ### Fields inherited from class org.opencv.dnn.Model

      `nativeObj`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `TextRecognitionModel​(long addr)` |
    `` | `TextRecognitionModel​(java.lang.String model)` | Create text recognition model from network represented in one of the supported formats Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method
    `` | `TextRecognitionModel​(java.lang.String model, java.lang.String config)` | Create text recognition model from network represented in one of the supported formats Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method
    `` | `TextRecognitionModel​(Net network)` | Create Text Recognition model from deep learning network Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static TextRecognitionModel` | `__fromPtr__​(long addr)` |
    `protected void` | `finalize()` |
    `java.lang.String` | `getDecodeType()` | Get the decoding method
    `java.util.List<java.lang.String>` | `getVocabulary()` | Get the vocabulary for recognition.
    `java.lang.String` | `recognize​(Mat frame)` | Given the `input` frame, create input blob, run net and return recognition result
    `void` | `recognize​(Mat frame, java.util.List<Mat> roiRects, java.util.List<java.lang.String> results)` | Given the `input` frame, create input blob, run net and return recognition result
    `TextRecognitionModel` | `setDecodeOptsCTCPrefixBeamSearch​(int beamSize)` | Set the decoding method options for `"CTC-prefix-beam-search"` decode usage
    `TextRecognitionModel` | `setDecodeOptsCTCPrefixBeamSearch​(int beamSize, int vocPruneSize)` | Set the decoding method options for `"CTC-prefix-beam-search"` decode usage
    `TextRecognitionModel` | `setDecodeType​(java.lang.String decodeType)` | Set the decoding method of translating the network output into string
    `TextRecognitionModel` | `setVocabulary​(java.util.List<java.lang.String> vocabulary)` | Set the vocabulary for recognition.

    - ### Methods inherited from class org.opencv.dnn.Model

      `enableWinograd, getNativeObjAddr, predict, setInputCrop, setInputMean, setInputParams, setInputParams, setInputParams, setInputParams, setInputParams, setInputParams, setInputScale, setInputSize, setInputSize, setInputSwapRB, setOutputNames, setPreferableBackend, setPreferableTarget`

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

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

- - ### Constructor Detail

    - #### TextRecognitionModel

          protected TextRecognitionModel​(long addr)

    - #### TextRecognitionModel

          public TextRecognitionModel​(Net network)

      Create Text Recognition model from deep learning network Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method
      Parameters:
        `network` - Net object

    - #### TextRecognitionModel

          public TextRecognitionModel​(java.lang.String model,
                                      java.lang.String config)

      Create text recognition model from network represented in one of the supported formats Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method
      Parameters:
        `model` - Binary file contains trained weights
        `config` - Text file contains network configuration

    - #### TextRecognitionModel

          public TextRecognitionModel​(java.lang.String model)

      Create text recognition model from network represented in one of the supported formats Call setDecodeType() and setVocabulary() after constructor to initialize the decoding method
      Parameters:
        `model` - Binary file contains trained weights

  - ### Method Detail

    - #### __fromPtr__

          public static TextRecognitionModel __fromPtr__​(long addr)

    - #### setDecodeType

          public TextRecognitionModel setDecodeType​(java.lang.String decodeType)

      Set the decoding method of translating the network output into string
      Parameters:
        `decodeType` - The decoding method of translating the network output into string, currently supported type: - `"CTC-greedy"` greedy decoding for the output of CTC-based methods - `"CTC-prefix-beam-search"` Prefix beam search decoding for the output of CTC-based methods
      Returns:
        automatically generated

    - #### getDecodeType

          public java.lang.String getDecodeType()

      Get the decoding method
      Returns:
        the decoding method

    - #### setDecodeOptsCTCPrefixBeamSearch

          public TextRecognitionModel setDecodeOptsCTCPrefixBeamSearch​(int beamSize,
                                                                       int vocPruneSize)

      Set the decoding method options for `"CTC-prefix-beam-search"` decode usage
      Parameters:
        `beamSize` - Beam size for search
        `vocPruneSize` - Parameter to optimize big vocabulary search, only take top `vocPruneSize` tokens in each search step, `vocPruneSize` <= 0 stands for disable this prune.
      Returns:
        automatically generated

    - #### setDecodeOptsCTCPrefixBeamSearch

          public TextRecognitionModel setDecodeOptsCTCPrefixBeamSearch​(int beamSize)

      Set the decoding method options for `"CTC-prefix-beam-search"` decode usage
      Parameters:
        `beamSize` - Beam size for search only take top `vocPruneSize` tokens in each search step, `vocPruneSize` <= 0 stands for disable this prune.
      Returns:
        automatically generated

    - #### setVocabulary

          public TextRecognitionModel setVocabulary​(java.util.List<java.lang.String> vocabulary)

      Set the vocabulary for recognition.
      Parameters:
        `vocabulary` - the associated vocabulary of the network.
      Returns:
        automatically generated

    - #### getVocabulary

          public java.util.List<java.lang.String> getVocabulary()

      Get the vocabulary for recognition.
      Returns:
        vocabulary the associated vocabulary

    - #### recognize

          public java.lang.String recognize​(Mat frame)

      Given the `input` frame, create input blob, run net and return recognition result
      Parameters:
        `frame` - The input image
      Returns:
        The text recognition result

    - #### recognize

          public void recognize​(Mat frame,
                                java.util.List<Mat> roiRects,
                                java.util.List<java.lang.String> results)

      Given the `input` frame, create input blob, run net and return recognition result
      Parameters:
        `frame` - The input image
        `roiRects` - List of text detection regions of interest (cv::Rect, CV_32SC4). ROIs is be cropped as the network inputs
        `results` - A set of text recognition results.

    - #### finalize

          protected void finalize()
                           throws java.lang.Throwable

      Overrides:
        `finalize` in class `Model`
      Throws:
        `java.lang.Throwable`