Modules | |
Partial List of Implemented Layers | |
Utilities for New Layers Registration | |
Classes | |
class | cv::dnn::BackendNode |
Derivatives of this class encapsulates functions of certain backends. More... | |
class | cv::dnn::BackendWrapper |
Derivatives of this class wraps cv::Mat for different backends and targets. More... | |
class | cv::dnn::ClassificationModel |
This class represents high-level API for classification models. More... | |
class | cv::dnn::DetectionModel |
This class represents high-level API for object detection networks. More... | |
class | cv::dnn::Dict |
This class implements name-value dictionary, values are instances of DictValue. More... | |
struct | cv::dnn::DictValue |
This struct stores the scalar value (or array) of one of the following type: double, cv::String or int64. More... | |
struct | cv::dnn::Image2BlobParams |
Processing params of image to blob. More... | |
class | cv::dnn::KeypointsModel |
This class represents high-level API for keypoints models. More... | |
class | cv::dnn::Layer |
This interface class allows to build new Layers - are building blocks of networks. More... | |
class | cv::dnn::LayerParams |
This class provides all data needed to initialize layer. More... | |
class | cv::dnn::Model |
This class is presented high-level API for neural networks. More... | |
class | cv::dnn::Net |
This class allows to create and manipulate comprehensive artificial neural networks. More... | |
class | cv::dnn::SegmentationModel |
This class represents high-level API for segmentation models. More... | |
class | cv::dnn::TextDetectionModel |
Base class for text detection networks. More... | |
class | cv::dnn::TextDetectionModel_DB |
This class represents high-level API for text detection DL networks compatible with DB model. More... | |
class | cv::dnn::TextDetectionModel_EAST |
This class represents high-level API for text detection DL networks compatible with EAST model. More... | |
class | cv::dnn::TextRecognitionModel |
This class represents high-level API for text recognition networks. More... | |
Typedefs | |
typedef std::map< std::string, std::vector< LayerFactory::Constructor > > | cv::dnn::LayerFactory_Impl |
typedef std::vector< int > | cv::dnn::MatShape |
Functions | |
Mat | cv::dnn::blobFromImage (InputArray image, double scalefactor=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false, int ddepth=CV_32F) |
Creates 4-dimensional blob from image. Optionally resizes and crops image from center, subtract mean values, scales values by scalefactor , swap Blue and Red channels. | |
void | cv::dnn::blobFromImage (InputArray image, OutputArray blob, double scalefactor=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false, int ddepth=CV_32F) |
Creates 4-dimensional blob from image. | |
Mat | cv::dnn::blobFromImages (InputArrayOfArrays images, double scalefactor=1.0, Size size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false, int ddepth=CV_32F) |
Creates 4-dimensional blob from series of images. Optionally resizes and crops images from center, subtract mean values, scales values by scalefactor , swap Blue and Red channels. | |
void | cv::dnn::blobFromImages (InputArrayOfArrays images, OutputArray blob, double scalefactor=1.0, Size size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false, int ddepth=CV_32F) |
Creates 4-dimensional blob from series of images. | |
Mat | cv::dnn::blobFromImagesWithParams (InputArrayOfArrays images, const Image2BlobParams ¶m=Image2BlobParams()) |
Creates 4-dimensional blob from series of images with given params. | |
void | cv::dnn::blobFromImagesWithParams (InputArrayOfArrays images, OutputArray blob, const Image2BlobParams ¶m=Image2BlobParams()) |
Mat | cv::dnn::blobFromImageWithParams (InputArray image, const Image2BlobParams ¶m=Image2BlobParams()) |
Creates 4-dimensional blob from image with given params. | |
void | cv::dnn::blobFromImageWithParams (InputArray image, OutputArray blob, const Image2BlobParams ¶m=Image2BlobParams()) |
void | cv::dnn::enableModelDiagnostics (bool isDiagnosticsMode) |
Enables detailed logging of the DNN model loading with CV DNN API. | |
std::vector< std::pair< Backend, Target > > | cv::dnn::getAvailableBackends () |
std::vector< Target > | cv::dnn::getAvailableTargets (dnn::Backend be) |
LayerFactory_Impl & | cv::dnn::getLayerFactoryImpl () |
Mutex & | cv::dnn::getLayerFactoryMutex () |
Get the mutex guarding LayerFactory_Impl, see getLayerFactoryImpl() function. | |
void | cv::dnn::imagesFromBlob (const cv::Mat &blob_, OutputArrayOfArrays images_) |
Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure (std::vector<cv::Mat>). | |
void | cv::dnn::NMSBoxes (const std::vector< Rect > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0) |
Performs non maximum suppression given boxes and corresponding scores. | |
void | cv::dnn::NMSBoxes (const std::vector< Rect2d > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0) |
void | cv::dnn::NMSBoxes (const std::vector< RotatedRect > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0) |
void | cv::dnn::NMSBoxesBatched (const std::vector< Rect > &bboxes, const std::vector< float > &scores, const std::vector< int > &class_ids, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0) |
Performs batched non maximum suppression on given boxes and corresponding scores across different classes. | |
void | cv::dnn::NMSBoxesBatched (const std::vector< Rect2d > &bboxes, const std::vector< float > &scores, const std::vector< int > &class_ids, const float score_threshold, const float nms_threshold, std::vector< int > &indices, const float eta=1.f, const int top_k=0) |
Net | cv::dnn::readNet (const String &framework, const std::vector< uchar > &bufferModel, const std::vector< uchar > &bufferConfig=std::vector< uchar >()) |
Read deep learning network represented in one of the supported formats. | |
Net | cv::dnn::readNet (const String &model, const String &config="", const String &framework="") |
Read deep learning network represented in one of the supported formats. | |
Net | cv::dnn::readNetFromCaffe (const char *bufferProto, size_t lenProto, const char *bufferModel=NULL, size_t lenModel=0) |
Reads a network model stored in Caffe model in memory. | |
Net | cv::dnn::readNetFromCaffe (const std::vector< uchar > &bufferProto, const std::vector< uchar > &bufferModel=std::vector< uchar >()) |
Reads a network model stored in Caffe model in memory. | |
Net | cv::dnn::readNetFromCaffe (const String &prototxt, const String &caffeModel=String()) |
Reads a network model stored in Caffe framework's format. | |
Net | cv::dnn::readNetFromDarknet (const char *bufferCfg, size_t lenCfg, const char *bufferModel=NULL, size_t lenModel=0) |
Reads a network model stored in Darknet model files. | |
Net | cv::dnn::readNetFromDarknet (const std::vector< uchar > &bufferCfg, const std::vector< uchar > &bufferModel=std::vector< uchar >()) |
Reads a network model stored in Darknet model files. | |
Net | cv::dnn::readNetFromDarknet (const String &cfgFile, const String &darknetModel=String()) |
Reads a network model stored in Darknet model files. | |
Net | cv::dnn::readNetFromModelOptimizer (const std::vector< uchar > &bufferModelConfig, const std::vector< uchar > &bufferWeights) |
Load a network from Intel's Model Optimizer intermediate representation. | |
Net | cv::dnn::readNetFromModelOptimizer (const String &xml, const String &bin) |
Load a network from Intel's Model Optimizer intermediate representation. | |
Net | cv::dnn::readNetFromModelOptimizer (const uchar *bufferModelConfigPtr, size_t bufferModelConfigSize, const uchar *bufferWeightsPtr, size_t bufferWeightsSize) |
Load a network from Intel's Model Optimizer intermediate representation. | |
Net | cv::dnn::readNetFromONNX (const char *buffer, size_t sizeBuffer) |
Reads a network model from ONNX in-memory buffer. | |
Net | cv::dnn::readNetFromONNX (const std::vector< uchar > &buffer) |
Reads a network model from ONNX in-memory buffer. | |
Net | cv::dnn::readNetFromONNX (const String &onnxFile) |
Reads a network model ONNX. | |
Net | cv::dnn::readNetFromTensorflow (const char *bufferModel, size_t lenModel, const char *bufferConfig=NULL, size_t lenConfig=0) |
Reads a network model stored in TensorFlow framework's format. | |
Net | cv::dnn::readNetFromTensorflow (const std::vector< uchar > &bufferModel, const std::vector< uchar > &bufferConfig=std::vector< uchar >()) |
Reads a network model stored in TensorFlow framework's format. | |
Net | cv::dnn::readNetFromTensorflow (const String &model, const String &config=String()) |
Reads a network model stored in TensorFlow framework's format. | |
Net | cv::dnn::readNetFromTFLite (const char *bufferModel, size_t lenModel) |
Reads a network model stored in TFLite framework's format. | |
Net | cv::dnn::readNetFromTFLite (const std::vector< uchar > &bufferModel) |
Reads a network model stored in TFLite framework's format. | |
Net | cv::dnn::readNetFromTFLite (const String &model) |
Reads a network model stored in TFLite framework's format. | |
Net | cv::dnn::readNetFromTorch (const String &model, bool isBinary=true, bool evaluate=true) |
Reads a network model stored in Torch7 framework's format. | |
Mat | cv::dnn::readTensorFromONNX (const String &path) |
Creates blob from .pb file. | |
Mat | cv::dnn::readTorchBlob (const String &filename, bool isBinary=true) |
Loads blob which was serialized as torch.Tensor object of Torch7 framework. | |
void | cv::dnn::shrinkCaffeModel (const String &src, const String &dst, const std::vector< String > &layersTypes=std::vector< String >()) |
Convert all weights of Caffe network to half precision floating point. | |
void | cv::dnn::softNMSBoxes (const std::vector< Rect > &bboxes, const std::vector< float > &scores, std::vector< float > &updated_scores, const float score_threshold, const float nms_threshold, std::vector< int > &indices, size_t top_k=0, const float sigma=0.5, SoftNMSMethod method=SoftNMSMethod::SOFTNMS_GAUSSIAN) |
Performs soft non maximum suppression given boxes and corresponding scores. Reference: https://arxiv.org/abs/1704.04503. | |
void | cv::dnn::writeTextGraph (const String &model, const String &output) |
Create a text representation for a binary network stored in protocol buffer format. | |
Detailed Description
This module contains:
- API for new layers creation, layers are building bricks of neural networks;
- set of built-in most-useful Layers;
- API to construct and modify comprehensive neural networks from layers;
- functionality for loading serialized networks models from different frameworks.
Functionality of this module is designed only for forward pass computations (i.e. network testing). A network training is in principle not supported.
Typedef Documentation
◆ LayerFactory_Impl
typedef std::map<std::string, std::vector<LayerFactory::Constructor> > cv::dnn::LayerFactory_Impl |
#include <opencv2/dnn/layer_reg.private.hpp>
◆ MatShape
typedef std::vector<int> cv::dnn::MatShape |
#include <opencv2/dnn/dnn.hpp>
Enumeration Type Documentation
◆ Backend
enum cv::dnn::Backend |
#include <opencv2/dnn/dnn.hpp>
Enum of computation backends supported by layers.
- See also
- Net::setPreferableBackend
Enumerator | |
---|---|
DNN_BACKEND_DEFAULT | DNN_BACKEND_DEFAULT equals to OPENCV_DNN_BACKEND_DEFAULT, which can be defined using CMake or a configuration parameter. |
DNN_BACKEND_HALIDE | |
DNN_BACKEND_INFERENCE_ENGINE | Intel OpenVINO computational backend
|
DNN_BACKEND_OPENCV | |
DNN_BACKEND_VKCOM | |
DNN_BACKEND_CUDA | |
DNN_BACKEND_WEBNN | |
DNN_BACKEND_TIMVX | |
DNN_BACKEND_CANN |
◆ DataLayout
enum cv::dnn::DataLayout |
#include <opencv2/dnn/dnn.hpp>
Enum of data layout for model inference.
- See also
- Image2BlobParams
◆ ImagePaddingMode
#include <opencv2/dnn/dnn.hpp>
Enum of image processing mode. To facilitate the specialization pre-processing requirements of the dnn model. For example, the letter box
often used in the Yolo series of models.
- See also
- Image2BlobParams
Enumerator | |
---|---|
DNN_PMODE_NULL | |
DNN_PMODE_CROP_CENTER | |
DNN_PMODE_LETTERBOX |
◆ SoftNMSMethod
|
strong |
#include <opencv2/dnn/dnn.hpp>
Enum of Soft NMS methods.
- See also
- softNMSBoxes
Enumerator | |
---|---|
SOFTNMS_LINEAR | |
SOFTNMS_GAUSSIAN |
◆ Target
enum cv::dnn::Target |
#include <opencv2/dnn/dnn.hpp>
Enum of target devices for computations.
- See also
- Net::setPreferableTarget
Function Documentation
◆ blobFromImage() [1/2]
Mat cv::dnn::blobFromImage | ( | InputArray | image, |
double | scalefactor = 1.0 , |
||
const Size & | size = Size() , |
||
const Scalar & | mean = Scalar() , |
||
bool | swapRB = false , |
||
bool | crop = false , |
||
int | ddepth = CV_32F |
||
) |
#include <opencv2/dnn/dnn.hpp>
Creates 4-dimensional blob from image. Optionally resizes and crops image
from center, subtract mean
values, scales values by scalefactor
, swap Blue and Red channels.
- Parameters
-
image input image (with 1-, 3- or 4-channels). scalefactor multiplier for images
values.size spatial size for output image mean scalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if image
has BGR ordering andswapRB
is true.swapRB flag which indicates that swap first and last channels in 3-channel image is necessary. crop flag which indicates whether image will be cropped after resize or not ddepth Depth of output blob. Choose CV_32F or CV_8U.
if crop
is true, input image is resized so one side after resize is equal to corresponding dimension in size
and another one is equal or larger. Then, crop from the center is performed. If crop
is false, direct resize without cropping and preserving aspect ratio is performed.
- Returns
- 4-dimensional Mat with NCHW dimensions order.
- Note
- The order and usage of
scalefactor
andmean
are (input - mean) * scalefactor.
◆ blobFromImage() [2/2]
void cv::dnn::blobFromImage | ( | InputArray | image, |
OutputArray | blob, | ||
double | scalefactor = 1.0 , |
||
const Size & | size = Size() , |
||
const Scalar & | mean = Scalar() , |
||
bool | swapRB = false , |
||
bool | crop = false , |
||
int | ddepth = CV_32F |
||
) |
#include <opencv2/dnn/dnn.hpp>
Creates 4-dimensional blob from image.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ blobFromImages() [1/2]
Mat cv::dnn::blobFromImages | ( | InputArrayOfArrays | images, |
double | scalefactor = 1.0 , |
||
Size | size = Size() , |
||
const Scalar & | mean = Scalar() , |
||
bool | swapRB = false , |
||
bool | crop = false , |
||
int | ddepth = CV_32F |
||
) |
#include <opencv2/dnn/dnn.hpp>
Creates 4-dimensional blob from series of images. Optionally resizes and crops images
from center, subtract mean
values, scales values by scalefactor
, swap Blue and Red channels.
- Parameters
-
images input images (all with 1-, 3- or 4-channels). size spatial size for output image mean scalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if image
has BGR ordering andswapRB
is true.scalefactor multiplier for images
values.swapRB flag which indicates that swap first and last channels in 3-channel image is necessary. crop flag which indicates whether image will be cropped after resize or not ddepth Depth of output blob. Choose CV_32F or CV_8U.
if crop
is true, input image is resized so one side after resize is equal to corresponding dimension in size
and another one is equal or larger. Then, crop from the center is performed. If crop
is false, direct resize without cropping and preserving aspect ratio is performed.
- Returns
- 4-dimensional Mat with NCHW dimensions order.
- Note
- The order and usage of
scalefactor
andmean
are (input - mean) * scalefactor.
◆ blobFromImages() [2/2]
void cv::dnn::blobFromImages | ( | InputArrayOfArrays | images, |
OutputArray | blob, | ||
double | scalefactor = 1.0 , |
||
Size | size = Size() , |
||
const Scalar & | mean = Scalar() , |
||
bool | swapRB = false , |
||
bool | crop = false , |
||
int | ddepth = CV_32F |
||
) |
#include <opencv2/dnn/dnn.hpp>
Creates 4-dimensional blob from series of images.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ blobFromImagesWithParams() [1/2]
Mat cv::dnn::blobFromImagesWithParams | ( | InputArrayOfArrays | images, |
const Image2BlobParams & | param = Image2BlobParams() |
||
) |
#include <opencv2/dnn/dnn.hpp>
Creates 4-dimensional blob from series of images with given params.
This function is an extension of blobFromImages to meet more image preprocess needs. Given input image and preprocessing parameters, and function outputs the blob.
- Parameters
-
images input image (all with 1-, 3- or 4-channels). param struct of Image2BlobParams, contains all parameters needed by processing of image to blob.
- Returns
- 4-dimensional Mat.
◆ blobFromImagesWithParams() [2/2]
void cv::dnn::blobFromImagesWithParams | ( | InputArrayOfArrays | images, |
OutputArray | blob, | ||
const Image2BlobParams & | param = Image2BlobParams() |
||
) |
#include <opencv2/dnn/dnn.hpp>
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ blobFromImageWithParams() [1/2]
Mat cv::dnn::blobFromImageWithParams | ( | InputArray | image, |
const Image2BlobParams & | param = Image2BlobParams() |
||
) |
#include <opencv2/dnn/dnn.hpp>
Creates 4-dimensional blob from image with given params.
This function is an extension of blobFromImage to meet more image preprocess needs. Given input image and preprocessing parameters, and function outputs the blob.
- Parameters
-
image input image (all with 1-, 3- or 4-channels). param struct of Image2BlobParams, contains all parameters needed by processing of image to blob.
- Returns
- 4-dimensional Mat.
◆ blobFromImageWithParams() [2/2]
void cv::dnn::blobFromImageWithParams | ( | InputArray | image, |
OutputArray | blob, | ||
const Image2BlobParams & | param = Image2BlobParams() |
||
) |
#include <opencv2/dnn/dnn.hpp>
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ enableModelDiagnostics()
void cv::dnn::enableModelDiagnostics | ( | bool | isDiagnosticsMode | ) |
#include <opencv2/dnn/dnn.hpp>
Enables detailed logging of the DNN model loading with CV DNN API.
- Parameters
-
[in] isDiagnosticsMode Indicates whether diagnostic mode should be set.
Diagnostic mode provides detailed logging of the model loading stage to explore potential problems (ex.: not implemented layer type).
- Note
- In diagnostic mode series of assertions will be skipped, it can lead to the expected application crash.
◆ getAvailableBackends()
#include <opencv2/dnn/dnn.hpp>
◆ getAvailableTargets()
std::vector< Target > cv::dnn::getAvailableTargets | ( | dnn::Backend | be | ) |
#include <opencv2/dnn/dnn.hpp>
◆ getLayerFactoryImpl()
LayerFactory_Impl & cv::dnn::getLayerFactoryImpl | ( | ) |
#include <opencv2/dnn/layer_reg.private.hpp>
Register layer types of DNN model.
- Note
- In order to thread-safely access the factory, see getLayerFactoryMutex() function.
◆ getLayerFactoryMutex()
Mutex & cv::dnn::getLayerFactoryMutex | ( | ) |
#include <opencv2/dnn/layer_reg.private.hpp>
Get the mutex guarding LayerFactory_Impl, see getLayerFactoryImpl() function.
◆ imagesFromBlob()
void cv::dnn::imagesFromBlob | ( | const cv::Mat & | blob_, |
OutputArrayOfArrays | images_ | ||
) |
#include <opencv2/dnn/dnn.hpp>
Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure (std::vector<cv::Mat>).
- Parameters
-
[in] blob_ 4 dimensional array (images, channels, height, width) in floating point precision (CV_32F) from which you would like to extract the images. [out] images_ array of 2D Mat containing the images extracted from the blob in floating point precision (CV_32F). They are non normalized neither mean added. The number of returned images equals the first dimension of the blob (batch size). Every image has a number of channels equals to the second dimension of the blob (depth).
◆ NMSBoxes() [1/3]
void cv::dnn::NMSBoxes | ( | const std::vector< Rect > & | bboxes, |
const std::vector< float > & | scores, | ||
const float | score_threshold, | ||
const float | nms_threshold, | ||
std::vector< int > & | indices, | ||
const float | eta = 1.f , |
||
const int | top_k = 0 |
||
) |
#include <opencv2/dnn/dnn.hpp>
Performs non maximum suppression given boxes and corresponding scores.
- Parameters
-
bboxes a set of bounding boxes to apply NMS. scores a set of corresponding confidences. score_threshold a threshold used to filter boxes by score. nms_threshold a threshold used in non maximum suppression. indices the kept indices of bboxes after NMS. eta a coefficient in adaptive threshold formula: \(nms\_threshold_{i+1}=eta\cdot nms\_threshold_i\). top_k if >0
, keep at mosttop_k
picked indices.
◆ NMSBoxes() [2/3]
void cv::dnn::NMSBoxes | ( | const std::vector< Rect2d > & | bboxes, |
const std::vector< float > & | scores, | ||
const float | score_threshold, | ||
const float | nms_threshold, | ||
std::vector< int > & | indices, | ||
const float | eta = 1.f , |
||
const int | top_k = 0 |
||
) |
#include <opencv2/dnn/dnn.hpp>
◆ NMSBoxes() [3/3]
void cv::dnn::NMSBoxes | ( | const std::vector< RotatedRect > & | bboxes, |
const std::vector< float > & | scores, | ||
const float | score_threshold, | ||
const float | nms_threshold, | ||
std::vector< int > & | indices, | ||
const float | eta = 1.f , |
||
const int | top_k = 0 |
||
) |
#include <opencv2/dnn/dnn.hpp>
◆ NMSBoxesBatched() [1/2]
void cv::dnn::NMSBoxesBatched | ( | const std::vector< Rect > & | bboxes, |
const std::vector< float > & | scores, | ||
const std::vector< int > & | class_ids, | ||
const float | score_threshold, | ||
const float | nms_threshold, | ||
std::vector< int > & | indices, | ||
const float | eta = 1.f , |
||
const int | top_k = 0 |
||
) |
#include <opencv2/dnn/dnn.hpp>
Performs batched non maximum suppression on given boxes and corresponding scores across different classes.
- Parameters
-
bboxes a set of bounding boxes to apply NMS. scores a set of corresponding confidences. class_ids a set of corresponding class ids. Ids are integer and usually start from 0. score_threshold a threshold used to filter boxes by score. nms_threshold a threshold used in non maximum suppression. indices the kept indices of bboxes after NMS. eta a coefficient in adaptive threshold formula: \(nms\_threshold_{i+1}=eta\cdot nms\_threshold_i\). top_k if >0
, keep at mosttop_k
picked indices.
◆ NMSBoxesBatched() [2/2]
void cv::dnn::NMSBoxesBatched | ( | const std::vector< Rect2d > & | bboxes, |
const std::vector< float > & | scores, | ||
const std::vector< int > & | class_ids, | ||
const float | score_threshold, | ||
const float | nms_threshold, | ||
std::vector< int > & | indices, | ||
const float | eta = 1.f , |
||
const int | top_k = 0 |
||
) |
#include <opencv2/dnn/dnn.hpp>
◆ readNet() [1/2]
Net cv::dnn::readNet | ( | const String & | framework, |
const std::vector< uchar > & | bufferModel, | ||
const std::vector< uchar > & | bufferConfig = std::vector< uchar >() |
||
) |
#include <opencv2/dnn/dnn.hpp>
Read deep learning network represented in one of the supported formats.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
[in] framework Name of origin framework. [in] bufferModel A buffer with a content of binary file with weights [in] bufferConfig A buffer with a content of text file contains network configuration.
- Returns
- Net object.
◆ readNet() [2/2]
Net cv::dnn::readNet | ( | const String & | model, |
const String & | config = "" , |
||
const String & | framework = "" |
||
) |
#include <opencv2/dnn/dnn.hpp>
Read deep learning network represented in one of the supported formats.
- Parameters
-
[in] model Binary file contains trained weights. The following file extensions are expected for models from different frameworks: *.caffemodel
(Caffe, http://caffe.berkeleyvision.org/)*.pb
(TensorFlow, https://www.tensorflow.org/)*.t7
|*.net
(Torch, http://torch.ch/)*.weights
(Darknet, https://pjreddie.com/darknet/)*.bin
(DLDT, https://software.intel.com/openvino-toolkit)*.onnx
(ONNX, https://onnx.ai/)
[in] config Text file contains network configuration. It could be a file with the following extensions: *.prototxt
(Caffe, http://caffe.berkeleyvision.org/)*.pbtxt
(TensorFlow, https://www.tensorflow.org/)*.cfg
(Darknet, https://pjreddie.com/darknet/)*.xml
(DLDT, https://software.intel.com/openvino-toolkit)
[in] framework Explicit framework name tag to determine a format.
- Returns
- Net object.
This function automatically detects an origin framework of trained model and calls an appropriate function such readNetFromCaffe, readNetFromTensorflow, readNetFromTorch or readNetFromDarknet. An order of model
and config
arguments does not matter.
◆ readNetFromCaffe() [1/3]
Net cv::dnn::readNetFromCaffe | ( | const char * | bufferProto, |
size_t | lenProto, | ||
const char * | bufferModel = NULL , |
||
size_t | lenModel = 0 |
||
) |
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in Caffe model in memory.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
bufferProto buffer containing the content of the .prototxt file lenProto length of bufferProto bufferModel buffer containing the content of the .caffemodel file lenModel length of bufferModel
- Returns
- Net object.
◆ readNetFromCaffe() [2/3]
Net cv::dnn::readNetFromCaffe | ( | const std::vector< uchar > & | bufferProto, |
const std::vector< uchar > & | bufferModel = std::vector< uchar >() |
||
) |
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in Caffe model in memory.
- Parameters
-
bufferProto buffer containing the content of the .prototxt file bufferModel buffer containing the content of the .caffemodel file
- Returns
- Net object.
◆ readNetFromCaffe() [3/3]
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in Caffe framework's format.
- Parameters
-
prototxt path to the .prototxt file with text description of the network architecture. caffeModel path to the .caffemodel file with learned network.
- Returns
- Net object.
◆ readNetFromDarknet() [1/3]
Net cv::dnn::readNetFromDarknet | ( | const char * | bufferCfg, |
size_t | lenCfg, | ||
const char * | bufferModel = NULL , |
||
size_t | lenModel = 0 |
||
) |
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in Darknet model files.
- Parameters
-
bufferCfg A buffer contains a content of .cfg file with text description of the network architecture. lenCfg Number of bytes to read from bufferCfg bufferModel A buffer contains a content of .weights file with learned network. lenModel Number of bytes to read from bufferModel
- Returns
- Net object.
◆ readNetFromDarknet() [2/3]
Net cv::dnn::readNetFromDarknet | ( | const std::vector< uchar > & | bufferCfg, |
const std::vector< uchar > & | bufferModel = std::vector< uchar >() |
||
) |
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in Darknet model files.
- Parameters
-
bufferCfg A buffer contains a content of .cfg file with text description of the network architecture. bufferModel A buffer contains a content of .weights file with learned network.
- Returns
- Net object.
◆ readNetFromDarknet() [3/3]
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in Darknet model files.
- Parameters
-
cfgFile path to the .cfg file with text description of the network architecture. darknetModel path to the .weights file with learned network.
- Returns
- Network object that ready to do forward, throw an exception in failure cases.
◆ readNetFromModelOptimizer() [1/3]
Net cv::dnn::readNetFromModelOptimizer | ( | const std::vector< uchar > & | bufferModelConfig, |
const std::vector< uchar > & | bufferWeights | ||
) |
#include <opencv2/dnn/dnn.hpp>
Load a network from Intel's Model Optimizer intermediate representation.
- Parameters
-
[in] bufferModelConfig Buffer contains XML configuration with network's topology. [in] bufferWeights Buffer contains binary data with trained weights.
◆ readNetFromModelOptimizer() [2/3]
#include <opencv2/dnn/dnn.hpp>
Load a network from Intel's Model Optimizer intermediate representation.
- Parameters
-
[in] xml XML configuration file with network's topology. [in] bin Binary file with trained weights.
◆ readNetFromModelOptimizer() [3/3]
Net cv::dnn::readNetFromModelOptimizer | ( | const uchar * | bufferModelConfigPtr, |
size_t | bufferModelConfigSize, | ||
const uchar * | bufferWeightsPtr, | ||
size_t | bufferWeightsSize | ||
) |
#include <opencv2/dnn/dnn.hpp>
Load a network from Intel's Model Optimizer intermediate representation.
- Parameters
-
[in] bufferModelConfigPtr Pointer to buffer which contains XML configuration with network's topology. [in] bufferModelConfigSize Binary size of XML configuration data. [in] bufferWeightsPtr Pointer to buffer which contains binary data with trained weights. [in] bufferWeightsSize Binary size of trained weights data.
◆ readNetFromONNX() [1/3]
Net cv::dnn::readNetFromONNX | ( | const char * | buffer, |
size_t | sizeBuffer | ||
) |
#include <opencv2/dnn/dnn.hpp>
Reads a network model from ONNX in-memory buffer.
- Parameters
-
buffer memory address of the first byte of the buffer. sizeBuffer size of the buffer.
- Returns
- Network object that ready to do forward, throw an exception in failure cases.
◆ readNetFromONNX() [2/3]
#include <opencv2/dnn/dnn.hpp>
Reads a network model from ONNX in-memory buffer.
- Parameters
-
buffer in-memory buffer that stores the ONNX model bytes.
- Returns
- Network object that ready to do forward, throw an exception in failure cases.
◆ readNetFromONNX() [3/3]
#include <opencv2/dnn/dnn.hpp>
Reads a network model ONNX.
- Parameters
-
onnxFile path to the .onnx file with text description of the network architecture.
- Returns
- Network object that ready to do forward, throw an exception in failure cases.
◆ readNetFromTensorflow() [1/3]
Net cv::dnn::readNetFromTensorflow | ( | const char * | bufferModel, |
size_t | lenModel, | ||
const char * | bufferConfig = NULL , |
||
size_t | lenConfig = 0 |
||
) |
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in TensorFlow framework's format.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
bufferModel buffer containing the content of the pb file lenModel length of bufferModel bufferConfig buffer containing the content of the pbtxt file lenConfig length of bufferConfig
◆ readNetFromTensorflow() [2/3]
Net cv::dnn::readNetFromTensorflow | ( | const std::vector< uchar > & | bufferModel, |
const std::vector< uchar > & | bufferConfig = std::vector< uchar >() |
||
) |
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in TensorFlow framework's format.
- Parameters
-
bufferModel buffer containing the content of the pb file bufferConfig buffer containing the content of the pbtxt file
- Returns
- Net object.
◆ readNetFromTensorflow() [3/3]
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in TensorFlow framework's format.
- Parameters
-
model path to the .pb file with binary protobuf description of the network architecture config path to the .pbtxt file that contains text graph definition in protobuf format. Resulting Net object is built by text graph using weights from a binary one that let us make it more flexible.
- Returns
- Net object.
◆ readNetFromTFLite() [1/3]
Net cv::dnn::readNetFromTFLite | ( | const char * | bufferModel, |
size_t | lenModel | ||
) |
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in TFLite framework's format.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
bufferModel buffer containing the content of the tflite file lenModel length of bufferModel
◆ readNetFromTFLite() [2/3]
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in TFLite framework's format.
- Parameters
-
bufferModel buffer containing the content of the tflite file
- Returns
- Net object.
◆ readNetFromTFLite() [3/3]
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in TFLite framework's format.
- Parameters
-
model path to the .tflite file with binary flatbuffers description of the network architecture
- Returns
- Net object.
◆ readNetFromTorch()
#include <opencv2/dnn/dnn.hpp>
Reads a network model stored in Torch7 framework's format.
- Parameters
-
model path to the file, dumped from Torch by using torch.save() function. isBinary specifies whether the network was serialized in ascii mode or binary. evaluate specifies testing phase of network. If true, it's similar to evaluate() method in Torch.
- Returns
- Net object.
- Note
- Ascii mode of Torch serializer is more preferable, because binary mode extensively use
long
type of C language, which has various bit-length on different systems.
The loading file must contain serialized nn.Module object with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors.
List of supported layers (i.e. object instances derived from Torch nn.Module class):
- nn.Sequential
- nn.Parallel
- nn.Concat
- nn.Linear
- nn.SpatialConvolution
- nn.SpatialMaxPooling, nn.SpatialAveragePooling
- nn.ReLU, nn.TanH, nn.Sigmoid
- nn.Reshape
- nn.SoftMax, nn.LogSoftMax
Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported.
◆ readTensorFromONNX()
#include <opencv2/dnn/dnn.hpp>
Creates blob from .pb file.
- Parameters
-
path to the .pb file with input tensor.
- Returns
- Mat.
◆ readTorchBlob()
#include <opencv2/dnn/dnn.hpp>
Loads blob which was serialized as torch.Tensor object of Torch7 framework.
- Warning
- This function has the same limitations as readNetFromTorch().
◆ shrinkCaffeModel()
void cv::dnn::shrinkCaffeModel | ( | const String & | src, |
const String & | dst, | ||
const std::vector< String > & | layersTypes = std::vector< String >() |
||
) |
#include <opencv2/dnn/dnn.hpp>
Convert all weights of Caffe network to half precision floating point.
- Parameters
-
src Path to origin model from Caffe framework contains single precision floating point weights (usually has .caffemodel
extension).dst Path to destination model with updated weights. layersTypes Set of layers types which parameters will be converted. By default, converts only Convolutional and Fully-Connected layers' weights.
- Note
- Shrinked model has no origin float32 weights so it can't be used in origin Caffe framework anymore. However the structure of data is taken from NVidia's Caffe fork: https://github.com/NVIDIA/caffe. So the resulting model may be used there.
◆ softNMSBoxes()
void cv::dnn::softNMSBoxes | ( | const std::vector< Rect > & | bboxes, |
const std::vector< float > & | scores, | ||
std::vector< float > & | updated_scores, | ||
const float | score_threshold, | ||
const float | nms_threshold, | ||
std::vector< int > & | indices, | ||
size_t | top_k = 0 , |
||
const float | sigma = 0.5 , |
||
SoftNMSMethod | method = SoftNMSMethod::SOFTNMS_GAUSSIAN |
||
) |
#include <opencv2/dnn/dnn.hpp>
Performs soft non maximum suppression given boxes and corresponding scores. Reference: https://arxiv.org/abs/1704.04503.
- Parameters
-
bboxes a set of bounding boxes to apply Soft NMS. scores a set of corresponding confidences. updated_scores a set of corresponding updated confidences. score_threshold a threshold used to filter boxes by score. nms_threshold a threshold used in non maximum suppression. indices the kept indices of bboxes after NMS. top_k keep at most top_k
picked indices.sigma parameter of Gaussian weighting. method Gaussian or linear.
- See also
- SoftNMSMethod
◆ writeTextGraph()
#include <opencv2/dnn/dnn.hpp>
Create a text representation for a binary network stored in protocol buffer format.
- Parameters
-
[in] model A path to binary network. [in] output A path to output text file to be created.
- Note
- To reduce output file size, trained weights are not included.