Modules
Classes
Derivatives of this class encapsulates functions of certain backends.
More...
Derivatives of this class wraps
cv::Mat for different backends and targets.
More...
This class implements name-value dictionary, values are instances of
DictValue.
More...
This struct stores the scalar value (or array) of one of the following type: double,
cv::String or int64.
More...
This interface class allows to build new Layers - are building blocks of networks.
More...
This class provides all data needed to initialize layer.
More...
This class allows to create and manipulate comprehensive artificial neural networks.
More...
Typedefs
Enumerations
Functions
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.
More...
Creates 4-dimensional blob from image.
More...
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.
More...
Creates 4-dimensional blob from series of images.
More...
Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure (std::vector<cv::Mat>).
More...
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.
More...
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)
Read deep learning network represented in one of the supported formats.
More...
Read deep learning network represented in one of the supported formats.
More...
Reads a network model stored in
Caffe framework's format.
More...
Reads a network model stored in Caffe model in memory.
More...
Reads a network model stored in Caffe model in memory.
More...
Load a network from Intel's Model Optimizer intermediate representation.
More...
Reads a network model stored in
Torch7 framework's format.
More...
Creates blob from .pb file.
More...
Loads blob which was serialized as torch.Tensor object of Torch7 framework.
More...
Release a Myriad device is binded by OpenCV.
More...
Convert all weights of Caffe network to half precision floating point.
More...
Create a text representation for a binary network stored in protocol buffer format.
More...
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
§ MatShape
Enumeration Type Documentation
§ Backend
Enum of computation backends supported by layers.
- See also
- Net::setPreferableBackend
| Enumerator |
|---|
| DNN_BACKEND_DEFAULT Python: cv.dnn.DNN_BACKEND_DEFAULT | DNN_BACKEND_DEFAULT equals to DNN_BACKEND_INFERENCE_ENGINE if OpenCV is built with Intel's Inference Engine library or DNN_BACKEND_OPENCV otherwise.
|
| DNN_BACKEND_HALIDE Python: cv.dnn.DNN_BACKEND_HALIDE |
| DNN_BACKEND_INFERENCE_ENGINE Python: cv.dnn.DNN_BACKEND_INFERENCE_ENGINE |
| DNN_BACKEND_OPENCV Python: cv.dnn.DNN_BACKEND_OPENCV |
| DNN_BACKEND_VKCOM Python: cv.dnn.DNN_BACKEND_VKCOM |
§ Target
Enum of target devices for computations.
- See also
- Net::setPreferableTarget
| Enumerator |
|---|
| DNN_TARGET_CPU Python: cv.dnn.DNN_TARGET_CPU |
| DNN_TARGET_OPENCL Python: cv.dnn.DNN_TARGET_OPENCL |
| DNN_TARGET_OPENCL_FP16 Python: cv.dnn.DNN_TARGET_OPENCL_FP16 |
| DNN_TARGET_MYRIAD Python: cv.dnn.DNN_TARGET_MYRIAD |
| DNN_TARGET_VULKAN Python: cv.dnn.DNN_TARGET_VULKAN |
Function Documentation
§ blobFromImage() [1/2]
double
scalefactor = 1.0,
bool
swapRB = false,
bool
crop = false,
)
| Python: |
|---|
| retval | = | cv.dnn.blobFromImage( | image[, scalefactor[, size[, mean[, swapRB[, crop[, ddepth]]]]]] | ) |
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).
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 and swapRB is true.
scalefactor multiplier for image 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.
- Examples:
- samples/dnn/classification.cpp, samples/dnn/colorization.cpp, samples/dnn/object_detection.cpp, samples/dnn/openpose.cpp, samples/dnn/segmentation.cpp, and samples/dnn/text_detection.cpp.
§ blobFromImage() [2/2]
double
scalefactor = 1.0,
bool
swapRB = false,
bool
crop = false,
)
| Python: |
|---|
| retval | = | cv.dnn.blobFromImage( | image[, scalefactor[, size[, mean[, swapRB[, crop[, ddepth]]]]]] | ) |
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]
double
scalefactor = 1.0,
bool
swapRB = false,
bool
crop = false,
)
| Python: |
|---|
| retval | = | cv.dnn.blobFromImages( | images[, scalefactor[, size[, mean[, swapRB[, crop[, ddepth]]]]]] | ) |
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 and swapRB 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.
§ blobFromImages() [2/2]
double
scalefactor = 1.0,
bool
swapRB = false,
bool
crop = false,
)
| Python: |
|---|
| retval | = | cv.dnn.blobFromImages( | images[, scalefactor[, size[, mean[, swapRB[, crop[, ddepth]]]]]] | ) |
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.
§ imagesFromBlob()
void cv::dnn::imagesFromBlob
(
const
cv::Mat &
blob_,
)
| Python: |
|---|
| images_ | = | cv.dnn.imagesFromBlob( | blob_[, images_] | ) |
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
)
| Python: |
|---|
| indices | = | cv.dnn.NMSBoxes( | bboxes, scores, score_threshold, nms_threshold[, eta[, top_k]] | ) |
| indices | = | cv.dnn.NMSBoxesRotated( | bboxes, scores, score_threshold, nms_threshold[, eta[, top_k]] | ) |
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 most top_k picked indices.
- Examples:
- samples/dnn/object_detection.cpp, and samples/dnn/text_detection.cpp.
§ 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
)
| Python: |
|---|
| indices | = | cv.dnn.NMSBoxes( | bboxes, scores, score_threshold, nms_threshold[, eta[, top_k]] | ) |
| indices | = | cv.dnn.NMSBoxesRotated( | bboxes, scores, score_threshold, nms_threshold[, eta[, top_k]] | ) |
§ 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
)
| Python: |
|---|
| indices | = | cv.dnn.NMSBoxes( | bboxes, scores, score_threshold, nms_threshold[, eta[, top_k]] | ) |
| indices | = | cv.dnn.NMSBoxesRotated( | bboxes, scores, score_threshold, nms_threshold[, eta[, top_k]] | ) |
§ readNet() [1/2]
)
| Python: |
|---|
| retval | = | cv.dnn.readNet( | model[, config[, framework]] | ) |
| retval | = | cv.dnn.readNet( | framework, bufferModel[, bufferConfig] | ) |
§ readNet() [2/2]
Net cv::dnn::readNet
(
const
String &
framework,
const std::vector<
uchar > &
bufferModel,
const std::vector<
uchar > &
bufferConfig =
std::vector< uchar >()
)
| Python: |
|---|
| retval | = | cv.dnn.readNet( | model[, config[, framework]] | ) |
| retval | = | cv.dnn.readNet( | framework, bufferModel[, bufferConfig] | ) |
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.
§ readNetFromCaffe() [1/3]
Net cv::dnn::readNetFromCaffe
(
const
String &
prototxt,
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromCaffe( | prototxt[, caffeModel] | ) |
| retval | = | cv.dnn.readNetFromCaffe( | bufferProto[, bufferModel] | ) |
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.
- Examples:
- samples/dnn/colorization.cpp, and samples/dnn/openpose.cpp.
§ readNetFromCaffe() [2/3]
Net cv::dnn::readNetFromCaffe
(
const std::vector<
uchar > &
bufferProto,
const std::vector<
uchar > &
bufferModel =
std::vector< uchar >()
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromCaffe( | prototxt[, caffeModel] | ) |
| retval | = | cv.dnn.readNetFromCaffe( | bufferProto[, bufferModel] | ) |
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]
Net cv::dnn::readNetFromCaffe
(
const char *
bufferProto,
size_t
lenProto,
const char *
bufferModel = NULL,
size_t
lenModel = 0
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromCaffe( | prototxt[, caffeModel] | ) |
| retval | = | cv.dnn.readNetFromCaffe( | bufferProto[, bufferModel] | ) |
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.
§ readNetFromDarknet() [1/3]
Net cv::dnn::readNetFromDarknet
(
const
String &
cfgFile,
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromDarknet( | cfgFile[, darknetModel] | ) |
| retval | = | cv.dnn.readNetFromDarknet( | bufferCfg[, bufferModel] | ) |
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.
-
Net object.
§ readNetFromDarknet() [2/3]
Net cv::dnn::readNetFromDarknet
(
const std::vector<
uchar > &
bufferCfg,
const std::vector<
uchar > &
bufferModel =
std::vector< uchar >()
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromDarknet( | cfgFile[, darknetModel] | ) |
| retval | = | cv.dnn.readNetFromDarknet( | bufferCfg[, bufferModel] | ) |
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]
Net cv::dnn::readNetFromDarknet
(
const char *
bufferCfg,
size_t
lenCfg,
const char *
bufferModel = NULL,
size_t
lenModel = 0
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromDarknet( | cfgFile[, darknetModel] | ) |
| retval | = | cv.dnn.readNetFromDarknet( | bufferCfg[, bufferModel] | ) |
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.
§ readNetFromModelOptimizer()
Net cv::dnn::readNetFromModelOptimizer
(
const
String &
xml,
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromModelOptimizer( | xml, bin | ) |
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.
- Returns
- Net object. Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine backend.
§ readNetFromONNX()
Net cv::dnn::readNetFromONNX
(
const
String &
onnxFile )
| Python: |
|---|
| retval | = | cv.dnn.readNetFromONNX( | onnxFile | ) |
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
String &
model,
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromTensorflow( | model[, config] | ) |
| retval | = | cv.dnn.readNetFromTensorflow( | bufferModel[, bufferConfig] | ) |
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.
§ readNetFromTensorflow() [2/3]
Net cv::dnn::readNetFromTensorflow
(
const std::vector<
uchar > &
bufferModel,
const std::vector<
uchar > &
bufferConfig =
std::vector< uchar >()
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromTensorflow( | model[, config] | ) |
| retval | = | cv.dnn.readNetFromTensorflow( | bufferModel[, bufferConfig] | ) |
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]
Net cv::dnn::readNetFromTensorflow
(
const char *
bufferModel,
size_t
lenModel,
const char *
bufferConfig = NULL,
size_t
lenConfig = 0
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromTensorflow( | model[, config] | ) |
| retval | = | cv.dnn.readNetFromTensorflow( | bufferModel[, bufferConfig] | ) |
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
§ readNetFromTorch()
Net cv::dnn::readNetFromTorch
(
const
String &
model,
bool
isBinary = true
)
| Python: |
|---|
| retval | = | cv.dnn.readNetFromTorch( | model[, isBinary] | ) |
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.
- 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()
Mat cv::dnn::readTensorFromONNX
(
const
String &
path )
| Python: |
|---|
| retval | = | cv.dnn.readTensorFromONNX( | path | ) |
Creates blob from .pb file.
- Parameters
-
path to the .pb file with input tensor.
- Returns
- Mat.
§ readTorchBlob()
Mat cv::dnn::readTorchBlob
(
const
String &
filename,
bool
isBinary = true
)
| Python: |
|---|
| retval | = | cv.dnn.readTorchBlob( | filename[, isBinary] | ) |
Loads blob which was serialized as torch.Tensor object of Torch7 framework.
- Warning
- This function has the same limitations as readNetFromTorch().
§ resetMyriadDevice()
void cv::dnn::resetMyriadDevice
(
)
| Python: |
|---|
| None | = | cv.dnn.resetMyriadDevice( | ) |
Release a Myriad device is binded by OpenCV.
Single Myriad device cannot be shared across multiple processes which uses Inference Engine's Myriad plugin.
§ shrinkCaffeModel()
void cv::dnn::shrinkCaffeModel
(
const
String &
src,
const std::vector<
String > &
layersTypes =
std::vector< String >()
)
| Python: |
|---|
| None | = | cv.dnn.shrinkCaffeModel( | src, dst[, layersTypes] | ) |
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.
§ writeTextGraph()
void cv::dnn::writeTextGraph
(
const
String &
model,
)
| Python: |
|---|
| None | = | cv.dnn.writeTextGraph( | model, output | ) |
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.