OpenCV  4.5.1
Open Source Computer Vision
Public Member Functions | Protected Attributes | List of all members
cv::dnn::Model Class Reference

This class is presented high-level API for neural networks. More...

#include <opencv2/dnn/dnn.hpp>

Inheritance diagram for cv::dnn::Model:
cv::dnn::ClassificationModel cv::dnn::DetectionModel cv::dnn::KeypointsModel cv::dnn::SegmentationModel cv::dnn::TextDetectionModel cv::dnn::TextRecognitionModel cv::dnn::TextDetectionModel_DB cv::dnn::TextDetectionModel_EAST

Public Member Functions

 Model ()
 
 Model (const Model &)=default
 
 Model (Model &&)=default
 
 Model (const String &model, const 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. More...
 
 Model (const Net &network)
 Create model from deep learning network. More...
 
Impl * getImpl () const
 
Impl & getImplRef () const
 
NetgetNetwork_ () const
 
NetgetNetwork_ ()
 
 operator Net & () const
 
Modeloperator= (const Model &)=default
 
Modeloperator= (Model &&)=default
 
void predict (InputArray frame, OutputArrayOfArrays outs) const
 Given the input frame, create input blob, run net and return the output blobs. More...
 
ModelsetInputCrop (bool crop)
 Set flag crop for frame. More...
 
ModelsetInputMean (const Scalar &mean)
 Set mean value for frame. More...
 
void setInputParams (double scale=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false)
 Set preprocessing parameters for frame. More...
 
ModelsetInputScale (double scale)
 Set scalefactor value for frame. More...
 
ModelsetInputSize (const Size &size)
 Set input size for frame. More...
 
ModelsetInputSize (int width, int height)
 
ModelsetInputSwapRB (bool swapRB)
 Set flag swapRB for frame. More...
 
ModelsetPreferableBackend (dnn::Backend backendId)
 
ModelsetPreferableTarget (dnn::Target targetId)
 

Protected Attributes

Ptr< Impl > impl
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Model() [1/5]

cv::dnn::Model::Model ( )
Python:
<dnn_Model object>=cv.dnn_Model(model[, config])
<dnn_Model object>=cv.dnn_Model(network)

◆ Model() [2/5]

cv::dnn::Model::Model ( const Model )
default
Python:
<dnn_Model object>=cv.dnn_Model(model[, config])
<dnn_Model object>=cv.dnn_Model(network)

◆ Model() [3/5]

cv::dnn::Model::Model ( Model &&  )
default
Python:
<dnn_Model object>=cv.dnn_Model(model[, config])
<dnn_Model object>=cv.dnn_Model(network)

◆ Model() [4/5]

cv::dnn::Model::Model ( const String model,
const String config = "" 
)
Python:
<dnn_Model object>=cv.dnn_Model(model[, config])
<dnn_Model object>=cv.dnn_Model(network)

Create model from deep learning network represented in one of the supported formats. An order of model and config arguments does not matter.

Parameters
[in]modelBinary file contains trained weights.
[in]configText file contains network configuration.

◆ Model() [5/5]

cv::dnn::Model::Model ( const Net network)
Python:
<dnn_Model object>=cv.dnn_Model(model[, config])
<dnn_Model object>=cv.dnn_Model(network)

Create model from deep learning network.

Parameters
[in]networkNet object.

Member Function Documentation

◆ getImpl()

Impl* cv::dnn::Model::getImpl ( ) const
inline

◆ getImplRef()

Impl& cv::dnn::Model::getImplRef ( ) const
inline

◆ getNetwork_() [1/2]

Net& cv::dnn::Model::getNetwork_ ( ) const

◆ getNetwork_() [2/2]

Net& cv::dnn::Model::getNetwork_ ( )
inline

◆ operator Net &()

cv::dnn::Model::operator Net & ( ) const
inline

◆ operator=() [1/2]

Model& cv::dnn::Model::operator= ( const Model )
default

◆ operator=() [2/2]

Model& cv::dnn::Model::operator= ( Model &&  )
default

◆ predict()

void cv::dnn::Model::predict ( InputArray  frame,
OutputArrayOfArrays  outs 
) const
Python:
outs=cv.dnn_Model.predict(frame[, outs])

Given the input frame, create input blob, run net and return the output blobs.

Parameters
[in]frameThe input image.
[out]outsAllocated output blobs, which will store results of the computation.

◆ setInputCrop()

Model& cv::dnn::Model::setInputCrop ( bool  crop)
Python:
retval=cv.dnn_Model.setInputCrop(crop)

Set flag crop for frame.

Parameters
[in]cropFlag which indicates whether image will be cropped after resize or not.

◆ setInputMean()

Model& cv::dnn::Model::setInputMean ( const Scalar mean)
Python:
retval=cv.dnn_Model.setInputMean(mean)

Set mean value for frame.

Parameters
[in]meanScalar with mean values which are subtracted from channels.

◆ setInputParams()

void cv::dnn::Model::setInputParams ( double  scale = 1.0,
const Size size = Size(),
const Scalar mean = Scalar(),
bool  swapRB = false,
bool  crop = false 
)
Python:
None=cv.dnn_Model.setInputParams([, scale[, size[, mean[, swapRB[, crop]]]]])

Set preprocessing parameters for frame.

Parameters
[in]sizeNew input size.
[in]meanScalar with mean values which are subtracted from channels.
[in]scaleMultiplier for frame values.
[in]swapRBFlag which indicates that swap first and last channels.
[in]cropFlag which indicates whether image will be cropped after resize or not. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

◆ setInputScale()

Model& cv::dnn::Model::setInputScale ( double  scale)
Python:
retval=cv.dnn_Model.setInputScale(scale)

Set scalefactor value for frame.

Parameters
[in]scaleMultiplier for frame values.

◆ setInputSize() [1/2]

Model& cv::dnn::Model::setInputSize ( const Size size)
Python:
retval=cv.dnn_Model.setInputSize(size)
retval=cv.dnn_Model.setInputSize(width, height)

Set input size for frame.

Parameters
[in]sizeNew input size.
Note
If shape of the new blob less than 0, then frame size not change.

◆ setInputSize() [2/2]

Model& cv::dnn::Model::setInputSize ( int  width,
int  height 
)
inline
Python:
retval=cv.dnn_Model.setInputSize(size)
retval=cv.dnn_Model.setInputSize(width, height)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]widthNew input width.
[in]heightNew input height.

◆ setInputSwapRB()

Model& cv::dnn::Model::setInputSwapRB ( bool  swapRB)
Python:
retval=cv.dnn_Model.setInputSwapRB(swapRB)

Set flag swapRB for frame.

Parameters
[in]swapRBFlag which indicates that swap first and last channels.

◆ setPreferableBackend()

Model& cv::dnn::Model::setPreferableBackend ( dnn::Backend  backendId)
Python:
retval=cv.dnn_Model.setPreferableBackend(backendId)

◆ setPreferableTarget()

Model& cv::dnn::Model::setPreferableTarget ( dnn::Target  targetId)
Python:
retval=cv.dnn_Model.setPreferableTarget(targetId)

Member Data Documentation

◆ impl

Ptr<Impl> cv::dnn::Model::impl
protected

The documentation for this class was generated from the following file: