Package org.opencv.dnn

## Class Model

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

- Direct Known Subclasses:
    `ClassificationModel`, `DetectionModel`, `KeypointsModel`, `SegmentationModel`, `TextDetectionModel`, `TextRecognitionModel`

      public class Model
      extends java.lang.Object

  This class is presented high-level API for neural networks. Model allows to set params for preprocessing input image. Model creates net from file with trained weights and config, sets preprocessing input and runs forward pass.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected long` | `nativeObj` |

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `Model​(long addr)` |
    `` | `Model​(java.lang.String model)` | Create model from deep learning network represented in one of the supported formats.
    `` | `Model​(java.lang.String model, java.lang.String config)` | Create model from deep learning network represented in one of the supported formats.
    `` | `Model​(Net network)` | Create model from deep learning network.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static Model` | `__fromPtr__​(long addr)` |
    `Model` | `enableWinograd​(boolean useWinograd)` |
    `protected void` | `finalize()` |
    `long` | `getNativeObjAddr()` |
    `void` | `predict​(Mat frame, java.util.List<Mat> outs)` | Given the `input` frame, create input blob, run net and return the output `blobs`.
    `Model` | `setInputCrop​(boolean crop)` | Set flag crop for frame.
    `Model` | `setInputMean​(Scalar mean)` | Set mean value for frame.
    `void` | `setInputParams()` | Set preprocessing parameters for frame.
    `void` | `setInputParams​(double scale)` | Set preprocessing parameters for frame.
    `void` | `setInputParams​(double scale, Size size)` | Set preprocessing parameters for frame.
    `void` | `setInputParams​(double scale, Size size, Scalar mean)` | Set preprocessing parameters for frame.
    `void` | `setInputParams​(double scale, Size size, Scalar mean, boolean swapRB)` | Set preprocessing parameters for frame.
    `void` | `setInputParams​(double scale, Size size, Scalar mean, boolean swapRB, boolean crop)` | Set preprocessing parameters for frame.
    `Model` | `setInputScale​(Scalar scale)` | Set scalefactor value for frame.
    `Model` | `setInputSize​(int width, int height)` |
    `Model` | `setInputSize​(Size size)` | Set input size for frame.
    `Model` | `setInputSwapRB​(boolean swapRB)` | Set flag swapRB for frame.
    `Model` | `setOutputNames​(java.util.List<java.lang.String> outNames)` | Set output names for frame.
    `Model` | `setPreferableBackend​(int backendId)` |
    `Model` | `setPreferableTarget​(int targetId)` |

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

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

- - ### Field Detail

    - #### nativeObj

          protected final long nativeObj

  - ### Constructor Detail

    - #### Model

          protected Model​(long addr)

    - #### Model

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

      Create model from deep learning network represented in one of the supported formats. An order of `model` and `config` arguments does not matter.
      Parameters:
        `model` - Binary file contains trained weights.
        `config` - Text file contains network configuration.

    - #### Model

          public Model​(java.lang.String model)

      Create model from deep learning network represented in one of the supported formats. An order of `model` and `config` arguments does not matter.
      Parameters:
        `model` - Binary file contains trained weights.

    - #### Model

          public Model​(Net network)

      Create model from deep learning network.
      Parameters:
        `network` - Net object.

  - ### Method Detail

    - #### getNativeObjAddr

          public long getNativeObjAddr()

    - #### __fromPtr__

          public static Model __fromPtr__​(long addr)

    - #### setInputSize

          public Model setInputSize​(Size size)

      Set input size for frame.
      Parameters:
        `size` - New input size. Note: If shape of the new blob less than 0, then frame size not change.
      Returns:
        automatically generated

    - #### setInputSize

          public Model setInputSize​(int width,
                                    int height)

      Parameters:
        `width` - New input width.
        `height` - New input height.
      Returns:
        automatically generated

    - #### setInputMean

          public Model setInputMean​(Scalar mean)

      Set mean value for frame.
      Parameters:
        `mean` - Scalar with mean values which are subtracted from channels.
      Returns:
        automatically generated

    - #### setInputScale

          public Model setInputScale​(Scalar scale)

      Set scalefactor value for frame.
      Parameters:
        `scale` - Multiplier for frame values.
      Returns:
        automatically generated

    - #### setInputCrop

          public Model setInputCrop​(boolean crop)

      Set flag crop for frame.
      Parameters:
        `crop` - Flag which indicates whether image will be cropped after resize or not.
      Returns:
        automatically generated

    - #### setInputSwapRB

          public Model setInputSwapRB​(boolean swapRB)

      Set flag swapRB for frame.
      Parameters:
        `swapRB` - Flag which indicates that swap first and last channels.
      Returns:
        automatically generated

    - #### setOutputNames

          public Model setOutputNames​(java.util.List<java.lang.String> outNames)

      Set output names for frame.
      Parameters:
        `outNames` - Names for output layers.
      Returns:
        automatically generated

    - #### setInputParams

          public void setInputParams​(double scale,
                                     Size size,
                                     Scalar mean,
                                     boolean swapRB,
                                     boolean crop)

      Set preprocessing parameters for frame.
      Parameters:
        `size` - New input size.
        `mean` - Scalar with mean values which are subtracted from channels.
        `scale` - Multiplier for frame values.
        `swapRB` - Flag which indicates that swap first and last channels.
        `crop` - Flag which indicates whether image will be cropped after resize or not. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

    - #### setInputParams

          public void setInputParams​(double scale,
                                     Size size,
                                     Scalar mean,
                                     boolean swapRB)

      Set preprocessing parameters for frame.
      Parameters:
        `size` - New input size.
        `mean` - Scalar with mean values which are subtracted from channels.
        `scale` - Multiplier for frame values.
        `swapRB` - Flag which indicates that swap first and last channels. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

    - #### setInputParams

          public void setInputParams​(double scale,
                                     Size size,
                                     Scalar mean)

      Set preprocessing parameters for frame.
      Parameters:
        `size` - New input size.
        `mean` - Scalar with mean values which are subtracted from channels.
        `scale` - Multiplier for frame values. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

    - #### setInputParams

          public void setInputParams​(double scale,
                                     Size size)

      Set preprocessing parameters for frame.
      Parameters:
        `size` - New input size.
        `scale` - Multiplier for frame values. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

    - #### setInputParams

          public void setInputParams​(double scale)

      Set preprocessing parameters for frame.
      Parameters:
        `scale` - Multiplier for frame values. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

    - #### setInputParams

          public void setInputParams()

      Set preprocessing parameters for frame. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

    - #### predict

          public void predict​(Mat frame,
                              java.util.List<Mat> outs)

      Given the `input` frame, create input blob, run net and return the output `blobs`.
      Parameters:
        `outs` - Allocated output blobs, which will store results of the computation.
        `frame` - automatically generated

    - #### setPreferableBackend

          public Model setPreferableBackend​(int backendId)

    - #### setPreferableTarget

          public Model setPreferableTarget​(int targetId)

    - #### enableWinograd

          public Model enableWinograd​(boolean useWinograd)

    - #### finalize

          protected void finalize()
                           throws java.lang.Throwable

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