Table of Contents

Class DnnInvoke

Namespace
Emgu.CV.Dnn
Assembly
Emgu.CV.dll

Entry points to the Open CV Dnn module

public static class DnnInvoke
Inheritance
DnnInvoke
Inherited Members

Properties

AvailableBackends

Get the list of available DNN Backends

public static BackendTargetPair[] AvailableBackends { get; }

Property Value

BackendTargetPair[]

Methods

BlobFromImage(IInputArray, IOutputArray, double, Size, MCvScalar, bool, bool, DepthType)

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.

public static void BlobFromImage(IInputArray image, IOutputArray blob, double scaleFactor = 1, Size size = default, MCvScalar mean = default, bool swapRB = false, bool crop = false, DepthType ddepth = DepthType.Cv32F)

Parameters

image IInputArray

Input image (with 1- or 3-channels).

blob IOutputArray

4-dimensional output array with NCHW dimensions order.

scaleFactor double

Multiplier for image values.

size Size

Spatial size for output image

mean MCvScalar

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.

swapRB bool

Flag which indicates that swap first and last channels in 3-channel image is necessary.

crop bool

Flag which indicates whether image will be cropped after resize or not

ddepth DepthType

Depth of output blob. Choose CV_32F or CV_8U.

BlobFromImage(IInputArray, double, Size, MCvScalar, bool, bool, DepthType)

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.

public static Mat BlobFromImage(IInputArray image, double scaleFactor = 1, Size size = default, MCvScalar mean = default, bool swapRB = false, bool crop = false, DepthType ddepth = DepthType.Cv32F)

Parameters

image IInputArray

Input image (with 1- or 3-channels).

scaleFactor double

Multiplier for image values.

size Size

Spatial size for output image

mean MCvScalar

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.

swapRB bool

Flag which indicates that swap first and last channels in 3-channel image is necessary.

crop bool

Flag which indicates whether image will be cropped after resize or not

ddepth DepthType

Depth of output blob. Choose CV_32F or CV_8U.

Returns

Mat

4-dimensional Mat with NCHW dimensions order.

BlobFromImages(IInputArrayOfArrays, IOutputArray, double, Size, MCvScalar, bool, bool, DepthType)

Creates 4-dimensional blob from series of images. Optionally resizes and crops images from center, subtract mean values, scales values by scale factor, swap Blue and Red channels.

public static void BlobFromImages(IInputArrayOfArrays images, IOutputArray blob, double scaleFactor = 1, Size size = default, MCvScalar mean = default, bool swapRB = false, bool crop = false, DepthType ddepth = DepthType.Cv32F)

Parameters

images IInputArrayOfArrays

input images (all with 1-, 3- or 4-channels).

blob IOutputArray

4-dimensional OutputArray with NCHW dimensions order.

scaleFactor double

multiplier for images values.

size Size

spatial size for output image

mean MCvScalar

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.

swapRB bool

flag which indicates that swap first and last channels in 3-channel image is necessary.

crop bool

flag which indicates whether image will be cropped after resize or not

ddepth DepthType

Depth of output blob. Choose CV_32F or CV_8U.

BlobFromImages(Mat[], double, Size, MCvScalar, bool, bool, DepthType)

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.

public static Mat BlobFromImages(Mat[] images, double scaleFactor = 1, Size size = default, MCvScalar mean = default, bool swapRB = false, bool crop = false, DepthType ddepth = DepthType.Cv32F)

Parameters

images Mat[]

Input images (all with 1- or 3-channels).

scaleFactor double

Multiplier for images values.

size Size

Spatial size for output image

mean MCvScalar

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.

swapRB bool

Flag which indicates that swap first and last channels in 3-channel image is necessary.

crop bool

Flag which indicates whether image will be cropped after resize or not

ddepth DepthType

Depth of output blob. Choose CV_32F or CV_8U.

Returns

Mat

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.

EnableModelDiagnostics(bool)

Enables detailed logging of the DNN model loading with CV DNN API. Diagnostic mode provides detailed logging of the model loading stage to explore potential problems(ex.: not implemented layer type).

public static void EnableModelDiagnostics(bool isDiagnosticsMode)

Parameters

isDiagnosticsMode bool

Indicates whether diagnostic mode should be set.

Remarks

In diagnostic mode series of assertions will be skipped, it can lead to the expected application crash.

ImagesFromBlob(Mat, IOutputArrayOfArrays)

Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure (std::vector<cv::Mat>).

public static void ImagesFromBlob(Mat blob, IOutputArrayOfArrays images)

Parameters

blob Mat

4 dimensional array (images, channels, height, width) in floating point precision (CV_32F) from which you would like to extract the images.

images IOutputArrayOfArrays

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(RotatedRect[], float[], float, float, float, int)

Performs non maximum suppression given boxes and corresponding scores.

public static int[] NMSBoxes(RotatedRect[] bboxes, float[] scores, float scoreThreshold, float nmsThreshold, float eta = 1, int topK = 0)

Parameters

bboxes RotatedRect[]

A set of bounding boxes to apply NMS.

scores float[]

A set of corresponding confidences.

scoreThreshold float

A threshold used to filter boxes by score.

nmsThreshold float

A threshold used in non maximum suppression.

eta float

A coefficient in adaptive threshold

topK int

If >0, keep at most top_k picked indices.

Returns

int[]

The indices of the boxes to keep after NMS

NMSBoxes(VectorOfRect, VectorOfFloat, float, float, VectorOfInt, float, int)

Performs non maximum suppression given boxes and corresponding scores.

public static void NMSBoxes(VectorOfRect bboxes, VectorOfFloat scores, float scoreThreshold, float nmsThreshold, VectorOfInt indices, float eta = 1, int topK = 0)

Parameters

bboxes VectorOfRect

A set of bounding boxes to apply NMS.

scores VectorOfFloat

A set of corresponding confidences.

scoreThreshold float

A threshold used to filter boxes by score.

nmsThreshold float

A threshold used in non maximum suppression.

indices VectorOfInt

The kept indices of bboxes after NMS.

eta float

A coefficient in adaptive threshold

topK int

If >0, keep at most top_k picked indices.

NMSBoxes(VectorOfRotatedRect, VectorOfFloat, float, float, VectorOfInt, float, int)

Performs non maximum suppression given boxes and corresponding scores.

public static void NMSBoxes(VectorOfRotatedRect bboxes, VectorOfFloat scores, float scoreThreshold, float nmsThreshold, VectorOfInt indices, float eta = 1, int topK = 0)

Parameters

bboxes VectorOfRotatedRect

A set of bounding boxes to apply NMS.

scores VectorOfFloat

A set of corresponding confidences.

scoreThreshold float

A threshold used to filter boxes by score.

nmsThreshold float

A threshold used in non maximum suppression.

indices VectorOfInt

The kept indices of bboxes after NMS.

eta float

A coefficient in adaptive threshold

topK int

If >0, keep at most top_k picked indices.

NMSBoxes(Rectangle[], float[], float, float, float, int)

Performs non maximum suppression given boxes and corresponding scores.

public static int[] NMSBoxes(Rectangle[] bboxes, float[] scores, float scoreThreshold, float nmsThreshold, float eta = 1, int topK = 0)

Parameters

bboxes Rectangle[]

A set of bounding boxes to apply NMS.

scores float[]

A set of corresponding confidences.

scoreThreshold float

A threshold used to filter boxes by score.

nmsThreshold float

A threshold used in non maximum suppression.

eta float

A coefficient in adaptive threshold

topK int

If >0, keep at most top_k picked indices.

Returns

int[]

The indices of the boxes to keep after NMS

ReadNet(string, string, string)

Read deep learning network represented in one of the supported formats.

public static Net ReadNet(string model, string config = null, string framework = null)

Parameters

model string

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)

config string

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)

framework string

Explicit framework name tag to determine a format.

Returns

Net

Net object.

ReadNetFromCaffe(byte[], byte[])

Reads a network model stored in Caffe framework's format.

public static Net ReadNetFromCaffe(byte[] prototxt, byte[] caffeModel = null)

Parameters

prototxt byte[]

Buffer containing the content of the .prototxt file

caffeModel byte[]

Buffer containing the content of the .caffemodel file

Returns

Net

Net object.

ReadNetFromCaffe(string, string)

Reads a network model stored in Caffe framework's format.

public static Net ReadNetFromCaffe(string prototxt, string caffeModel = null)

Parameters

prototxt string

path to the .prototxt file with text description of the network architecture.

caffeModel string

path to the .caffemodel file with learned network.

Returns

Net

Net object.

ReadNetFromDarknet(byte[], byte[])

Reads a network model stored in Darknet model files.

public static Net ReadNetFromDarknet(byte[] bufferCfg, byte[] bufferModel = null)

Parameters

bufferCfg byte[]

Buffer containing the content of the .cfg file with text description of the network architecture.

bufferModel byte[]

Buffer containing the content of the the .weights file with learned network.

Returns

Net

Net object.

ReadNetFromDarknet(string, string)

Reads a network model stored in Darknet model files.

public static Net ReadNetFromDarknet(string cfgFile, string darknetModel = null)

Parameters

cfgFile string

path to the .cfg file with text description of the network architecture.

darknetModel string

path to the .weights file with learned network.

Returns

Net

Network object that ready to do forward, throw an exception in failure cases.

ReadNetFromModelOptimizer(string, string)

Load a network from Intel's Model Optimizer intermediate representation.

public static Net ReadNetFromModelOptimizer(string xml, string bin)

Parameters

xml string

XML configuration file with network's topology.

bin string

Binary file with trained weights.

Returns

Net

Net object. Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine backend.

ReadNetFromONNX(string)

Reads a network model ONNX.

public static Net ReadNetFromONNX(string onnxFile)

Parameters

onnxFile string

Path to the .onnx file with text description of the network architecture.

Returns

Net

Network object that ready to do forward, throw an exception in failure cases.

ReadNetFromTFLite(byte[])

Reads a network model stored in TFLite framework's format.

public static Net ReadNetFromTFLite(byte[] model)

Parameters

model byte[]

buffer containing the content of the tflite file

Returns

Net

Net object

ReadNetFromTFLite(string)

Reads a network model stored in TFLite framework's format.

public static Net ReadNetFromTFLite(string model)

Parameters

model string

Returns

Net

Net object

ReadNetFromTensorflow(byte[], byte[])

Reads a network model stored in TensorFlow framework's format.

public static Net ReadNetFromTensorflow(byte[] model, byte[] config = null)

Parameters

model byte[]

buffer containing the content of the pb file

config byte[]

buffer containing the content of the pbtxt file

Returns

Net

Net object

ReadNetFromTensorflow(string, string)

Reads a network model stored in TensorFlow framework's format.

public static Net ReadNetFromTensorflow(string model, string config = null)

Parameters

model string

path to the .pb file with binary protobuf description of the network architecture

config string

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

Net object.

ReadNetFromTorch(string, bool, bool)

Reads a network model stored in Torch7 framework's format.

public static Net ReadNetFromTorch(string model, bool isBinary = true, bool evaluate = true)

Parameters

model string

Path to the file, dumped from Torch by using torch.save() function.

isBinary bool

Specifies whether the network was serialized in ascii mode or binary.

evaluate bool

Specifies testing phase of network. If true, it's similar to evaluate() method in Torch.

Returns

Net

Net object.

ReadTensorFromONNX(string)

Creates blob from .pb file.

public static Mat ReadTensorFromONNX(string path)

Parameters

path string

Path to the .pb file with input tensor.

Returns

Mat

The blob

ReadTorchBlob(string, bool)

Loads blob which was serialized as torch.Tensor object of Torch7 framework.

public static Mat ReadTorchBlob(string fileName, bool isBinary = true)

Parameters

fileName string

The file name

isBinary bool

Specifies whether the blob was serialized in ascii mode or binary.

Returns

Mat

The tensor

ShrinkCaffeModel(string, string)

Convert all weights of Caffe network to half precision floating point

public static void ShrinkCaffeModel(string src, string dst)

Parameters

src string

Path to origin model from Caffe framework contains single precision floating point weights (usually has .caffemodel extension).

dst string

Path to destination model with updated weights.

SoftNMSBoxes(VectorOfRect, VectorOfFloat, VectorOfFloat, float, float, VectorOfInt, int, float, SoftNMSMethod)

Performs soft non maximum suppression given boxes and corresponding scores. Reference: https://arxiv.org/abs/1704.04503

public static void SoftNMSBoxes(VectorOfRect bboxes, VectorOfFloat scores, VectorOfFloat updatedScores, float scoreThreshold, float nmsThreshold, VectorOfInt indices, int topK = 0, float sigma = 0.5, SoftNMSMethod method = SoftNMSMethod.Gaussian)

Parameters

bboxes VectorOfRect

A set of bounding boxes to apply Soft NMS.

scores VectorOfFloat

A set of corresponding confidences.

updatedScores VectorOfFloat

A set of corresponding updated confidences.

scoreThreshold float

A threshold used to filter boxes by score.

nmsThreshold float

A threshold used in non maximum suppression.

indices VectorOfInt

The kept indices of bboxes after NMS.

topK int

Keep at most topK picked indices.

sigma float

Parameter of Gaussian weighting.

method SoftNMSMethod

Gaussian or linear.

WriteTextGraph(string, string)

Create a text representation for a binary network stored in protocol buffer format.

public static void WriteTextGraph(string model, string output)

Parameters

model string

A path to binary network.

output string

A path to output text file to be created.