Class DnnInvoke
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
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
IInputArrayInput image (with 1- or 3-channels).
blob
IOutputArray4-dimensional output array with NCHW dimensions order.
scaleFactor
doubleMultiplier for image values.
size
SizeSpatial size for output image
mean
MCvScalarScalar 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
boolFlag which indicates that swap first and last channels in 3-channel image is necessary.
crop
boolFlag which indicates whether image will be cropped after resize or not
ddepth
DepthTypeDepth 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
IInputArrayInput image (with 1- or 3-channels).
scaleFactor
doubleMultiplier for image values.
size
SizeSpatial size for output image
mean
MCvScalarScalar 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
boolFlag which indicates that swap first and last channels in 3-channel image is necessary.
crop
boolFlag which indicates whether image will be cropped after resize or not
ddepth
DepthTypeDepth 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
IInputArrayOfArraysinput images (all with 1-, 3- or 4-channels).
blob
IOutputArray4-dimensional OutputArray with NCHW dimensions order.
scaleFactor
doublemultiplier for images values.
size
Sizespatial size for output image
mean
MCvScalarscalar 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
boolflag which indicates that swap first and last channels in 3-channel image is necessary.
crop
boolflag which indicates whether image will be cropped after resize or not
ddepth
DepthTypeDepth 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
doubleMultiplier for images values.
size
SizeSpatial size for output image
mean
MCvScalarScalar 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
boolFlag which indicates that swap first and last channels in 3-channel image is necessary.
crop
boolFlag which indicates whether image will be cropped after resize or not
ddepth
DepthTypeDepth 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
boolIndicates 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
Mat4 dimensional array (images, channels, height, width) in floating point precision (CV_32F) from which you would like to extract the images.
images
IOutputArrayOfArraysArray 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
floatA threshold used to filter boxes by score.
nmsThreshold
floatA threshold used in non maximum suppression.
eta
floatA coefficient in adaptive threshold
topK
intIf >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
VectorOfRectA set of bounding boxes to apply NMS.
scores
VectorOfFloatA set of corresponding confidences.
scoreThreshold
floatA threshold used to filter boxes by score.
nmsThreshold
floatA threshold used in non maximum suppression.
indices
VectorOfIntThe kept indices of bboxes after NMS.
eta
floatA coefficient in adaptive threshold
topK
intIf >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
VectorOfRotatedRectA set of bounding boxes to apply NMS.
scores
VectorOfFloatA set of corresponding confidences.
scoreThreshold
floatA threshold used to filter boxes by score.
nmsThreshold
floatA threshold used in non maximum suppression.
indices
VectorOfIntThe kept indices of bboxes after NMS.
eta
floatA coefficient in adaptive threshold
topK
intIf >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
floatA threshold used to filter boxes by score.
nmsThreshold
floatA threshold used in non maximum suppression.
eta
floatA coefficient in adaptive threshold
topK
intIf >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
stringBinary 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
stringText 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
stringExplicit 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
stringpath to the .prototxt file with text description of the network architecture.
caffeModel
stringpath 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
stringpath to the .cfg file with text description of the network architecture.
darknetModel
stringpath 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
stringXML configuration file with network's topology.
bin
stringBinary 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
stringPath 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
stringpath to the .pb file with binary protobuf description of the network architecture
config
stringpath 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
stringPath to the file, dumped from Torch by using torch.save() function.
isBinary
boolSpecifies whether the network was serialized in ascii mode or binary.
evaluate
boolSpecifies 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
stringPath 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
stringThe file name
isBinary
boolSpecifies 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
stringPath to origin model from Caffe framework contains single precision floating point weights (usually has .caffemodel extension).
dst
stringPath 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
VectorOfRectA set of bounding boxes to apply Soft NMS.
scores
VectorOfFloatA set of corresponding confidences.
updatedScores
VectorOfFloatA set of corresponding updated confidences.
scoreThreshold
floatA threshold used to filter boxes by score.
nmsThreshold
floatA threshold used in non maximum suppression.
indices
VectorOfIntThe kept indices of bboxes after NMS.
topK
intKeep at most
topK
picked indices.sigma
floatParameter of Gaussian weighting.
method
SoftNMSMethodGaussian 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)