Class CvDnn
cv::dnn functions
Inheritance
Inherited Members
Namespace: OpenCvSharp.Dnn
Assembly: OpenCvSharp.dll
Syntax
public static class CvDnn
Methods
| Improve this Doc View SourceBlobFromImage(Mat, Double, Size, Scalar, Boolean, Boolean)
Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
public static Mat BlobFromImage(Mat image, double scaleFactor = 1, Size size = default(Size), Scalar mean = default(Scalar), bool swapRB = true, bool crop = true)
Parameters
Type | Name | Description |
---|---|---|
Mat | image | input image (with 1- or 3-channels). |
System.Double | scaleFactor | multiplier for @p image values. |
OpenCvSharp.Size | size | spatial size for output image |
OpenCvSharp.Scalar | mean | scalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. |
System.Boolean | swapRB | flag which indicates that swap first and last channels in 3-channel image is necessary. |
System.Boolean | crop | flag which indicates whether image will be cropped after resize or not |
Returns
Type | Description |
---|---|
Mat | 4-dimansional Mat with NCHW dimensions order. |
Remarks
if @p crop is true, input image is resized so one side after resize is equal to corresponing dimension in @p size and another one is equal or larger.Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
BlobFromImages(IEnumerable<Mat>, Double, Size, Scalar, Boolean, Boolean)
Creates 4-dimensional blob from series of images. Optionally resizes and crops @p images from center, subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
Declaration
public static Mat BlobFromImages(IEnumerable<Mat> images, double scaleFactor, Size size = default(Size), Scalar mean = default(Scalar), bool swapRB = true, bool crop = true)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Mat> | images | input images (all with 1- or 3-channels). |
System.Double | scaleFactor | multiplier for @p image values. |
OpenCvSharp.Size | size | spatial size for output image |
OpenCvSharp.Scalar | mean | scalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. |
System.Boolean | swapRB | flag which indicates that swap first and last channels in 3-channel image is necessary. |
System.Boolean | crop | flag which indicates whether image will be cropped after resize or not |
Returns
Type | Description |
---|---|
Mat | 4-dimansional Mat with NCHW dimensions order. |
Remarks
if @p crop is true, input image is resized so one side after resize is equal to corresponing dimension in @p size and another one is equal or larger.Then, crop from the center is performed. If @p crop is false, direct resize without cropping and preserving aspect ratio is performed.
NMSBoxes(IEnumerable<Rect>, IEnumerable<Single>, Single, Single, out Int32[], Single, Int32)
Performs non maximum suppression given boxes and corresponding scores.
Declaration
public static void NMSBoxes(IEnumerable<Rect> bboxes, IEnumerable<float> scores, float scoreThreshold, float nmsThreshold, out int[] indices, float eta = 1F, int topK = 0)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<OpenCvSharp.Rect> | bboxes | a set of bounding boxes to apply NMS. |
IEnumerable<System.Single> | scores | a set of corresponding confidences. |
System.Single | scoreThreshold | a threshold used to filter boxes by score. |
System.Single | nmsThreshold | a threshold used in non maximum suppression. |
System.Int32[] | indices | the kept indices of bboxes after NMS. |
System.Single | eta | a coefficient in adaptive threshold formula |
System.Int32 | topK | if |
NMSBoxes(IEnumerable<Rect2d>, IEnumerable<Single>, Single, Single, out Int32[], Single, Int32)
Performs non maximum suppression given boxes and corresponding scores.
Declaration
public static void NMSBoxes(IEnumerable<Rect2d> bboxes, IEnumerable<float> scores, float scoreThreshold, float nmsThreshold, out int[] indices, float eta = 1F, int topK = 0)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<OpenCvSharp.Rect2d> | bboxes | a set of bounding boxes to apply NMS. |
IEnumerable<System.Single> | scores | a set of corresponding confidences. |
System.Single | scoreThreshold | a threshold used to filter boxes by score. |
System.Single | nmsThreshold | a threshold used in non maximum suppression. |
System.Int32[] | indices | the kept indices of bboxes after NMS. |
System.Single | eta | a coefficient in adaptive threshold formula |
System.Int32 | topK | if |
NMSBoxes(IEnumerable<RotatedRect>, IEnumerable<Single>, Single, Single, out Int32[], Single, Int32)
Performs non maximum suppression given boxes and corresponding scores.
Declaration
public static void NMSBoxes(IEnumerable<RotatedRect> bboxes, IEnumerable<float> scores, float scoreThreshold, float nmsThreshold, out int[] indices, float eta = 1F, int topK = 0)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<OpenCvSharp.RotatedRect> | bboxes | a set of bounding boxes to apply NMS. |
IEnumerable<System.Single> | scores | a set of corresponding confidences. |
System.Single | scoreThreshold | a threshold used to filter boxes by score. |
System.Single | nmsThreshold | a threshold used in non maximum suppression. |
System.Int32[] | indices | the kept indices of bboxes after NMS. |
System.Single | eta | a coefficient in adaptive threshold formula |
System.Int32 | topK | if |
ReadNet(String, String, String)
Read deep learning network represented in one of the supported formats.
This function automatically detects an origin framework of trained model and calls an appropriate function such @ref readNetFromCaffe, @ref readNetFromTensorflow,
Declaration
public static Net ReadNet(string model, string config = "", string framework = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | model | Binary file contains trained weights. The following file
|
System.String | config | Text file contains network configuration. It could be a
|
System.String | framework | Explicit framework name tag to determine a format. |
Returns
Type | Description |
---|---|
Net |
ReadNetFromCaffe(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>)
Reads a network model stored in Caffe model files from memory.
Declaration
public static Net ReadNetFromCaffe(ReadOnlySpan<byte> bufferProto, ReadOnlySpan<byte> bufferModel = null)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<System.Byte> | bufferProto | buffer containing the content of the .prototxt file |
ReadOnlySpan<System.Byte> | bufferModel | buffer containing the content of the .caffemodel file |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from createCaffeImporter and Net::populateNet calls.
ReadNetFromCaffe(Stream, Nullable<Stream>)
Reads a network model stored in Caffe model files from Stream.
Declaration
public static Net ReadNetFromCaffe(Stream bufferProto, Stream? bufferModel = null)
Parameters
Type | Name | Description |
---|---|---|
Stream | bufferProto | buffer containing the content of the .prototxt file |
System.Nullable<Stream> | bufferModel | buffer containing the content of the .caffemodel file |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from createCaffeImporter and Net::populateNet calls.
ReadNetFromCaffe(Byte[], Byte[])
Reads a network model stored in Caffe model files from memory.
Declaration
public static Net ReadNetFromCaffe(byte[] bufferProto, byte[] bufferModel = null)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bufferProto | buffer containing the content of the .prototxt file |
System.Byte[] | bufferModel | buffer containing the content of the .caffemodel file |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from createCaffeImporter and Net::populateNet calls.
ReadNetFromCaffe(String, String)
Reads a network model stored in Caffe model files.
Declaration
public static Net ReadNetFromCaffe(string prototxt, string caffeModel = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | prototxt | path to the .prototxt file with text description of the network architecture. |
System.String | caffeModel | path to the .caffemodel file with learned network. |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from createCaffeImporter and Net::populateNet calls.
ReadNetFromDarknet(Stream, Nullable<Stream>)
Reads a network model stored in Darknet (https://pjreddie.com/darknet/) model files from stream.
Declaration
public static Net ReadNetFromDarknet(Stream bufferCfg, Stream? bufferModel = null)
Parameters
Type | Name | Description |
---|---|---|
Stream | bufferCfg | A buffer contains a content of .cfg file with text description of the network architecture. |
System.Nullable<Stream> | bufferModel | A buffer contains a content of .weights file with learned network. |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from DarknetImporter and Net::populateNet calls.
ReadNetFromDarknet(Byte[], Byte[])
Reads a network model stored in Darknet (https://pjreddie.com/darknet/) model files from memory.
Declaration
public static Net ReadNetFromDarknet(byte[] bufferCfg, byte[] bufferModel = null)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bufferCfg | A buffer contains a content of .cfg file with text description of the network architecture. |
System.Byte[] | bufferModel | A buffer contains a content of .weights file with learned network. |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from DarknetImporter and Net::populateNet calls.
ReadNetFromDarknet(String, String)
Reads a network model stored in Darknet (https://pjreddie.com/darknet/) model files.
Declaration
public static Net ReadNetFromDarknet(string cfgFile, string darknetModel = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | cfgFile | path to the .cfg file with text description of the network architecture. |
System.String | darknetModel | path to the .weights file with learned network. |
Returns
Type | Description |
---|---|
Net | Network object that ready to do forward, throw an exception in failure cases. |
Remarks
This is shortcut consisting from DarknetImporter and Net::populateNet calls.
ReadNetFromOnnx(ReadOnlySpan<Byte>)
Reads a network model ONNX https://onnx.ai/ from memory
Declaration
public static Net ReadNetFromOnnx(ReadOnlySpan<byte> onnxFileData)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<System.Byte> | onnxFileData | memory of the first byte of the buffer. |
Returns
Type | Description |
---|---|
Net |
ReadNetFromOnnx(Stream)
Reads a network model ONNX https://onnx.ai/ from stream.
Declaration
public static Net ReadNetFromOnnx(Stream onnxFileStream)
Parameters
Type | Name | Description |
---|---|---|
Stream | onnxFileStream | memory of the first byte of the buffer. |
Returns
Type | Description |
---|---|
Net |
ReadNetFromOnnx(Byte[])
Reads a network model ONNX https://onnx.ai/ from memory
Declaration
public static Net ReadNetFromOnnx(byte[] onnxFileData)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | onnxFileData | memory of the first byte of the buffer. |
Returns
Type | Description |
---|---|
Net |
ReadNetFromOnnx(String)
Reads a network model ONNX https://onnx.ai/ from memory
Declaration
public static Net ReadNetFromOnnx(string onnxFile)
Parameters
Type | Name | Description |
---|---|---|
System.String | onnxFile |
Returns
Type | Description |
---|---|
Net |
ReadNetFromTensorflow(Stream, Nullable<Stream>)
Reads a network model stored in Tensorflow model file from stream.
Declaration
public static Net ReadNetFromTensorflow(Stream bufferModel, Stream? bufferConfig = null)
Parameters
Type | Name | Description |
---|---|---|
Stream | bufferModel | buffer containing the content of the pb file |
System.Nullable<Stream> | bufferConfig | buffer containing the content of the pbtxt file (optional) |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from createTensorflowImporter and Net::populateNet calls.
ReadNetFromTensorflow(Byte[], Byte[])
Reads a network model stored in Tensorflow model file from memory.
Declaration
public static Net ReadNetFromTensorflow(byte[] bufferModel, byte[] bufferConfig = null)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bufferModel | buffer containing the content of the pb file |
System.Byte[] | bufferConfig | buffer containing the content of the pbtxt file (optional) |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from createTensorflowImporter and Net::populateNet calls.
ReadNetFromTensorflow(String, String)
Reads a network model stored in Tensorflow model file.
Declaration
public static Net ReadNetFromTensorflow(string model, string config = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | model | path to the .pb file with binary protobuf description of the network architecture |
System.String | config | path to the .pbtxt file that contains text graph definition in protobuf format. |
Returns
Type | Description |
---|---|
Net | Resulting Net object is built by text graph using weights from a binary one that let us make it more flexible. |
Remarks
This is shortcut consisting from createTensorflowImporter and Net::populateNet calls.
ReadNetFromTorch(String, Boolean)
Reads a network model stored in Torch model file.
Declaration
public static Net ReadNetFromTorch(string model, bool isBinary = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | model | |
System.Boolean | isBinary |
Returns
Type | Description |
---|---|
Net |
Remarks
This is shortcut consisting from createTorchImporter and Net::populateNet calls.
ReadTensorFromONNX(String)
Creates blob from .pb file.
Declaration
public static Mat ReadTensorFromONNX(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | path to the .pb file with input tensor. |
Returns
Type | Description |
---|---|
Mat |
ReadTorchBlob(String, Boolean)
Loads blob which was serialized as torch.Tensor object of Torch7 framework.
Declaration
public static Mat ReadTorchBlob(string fileName, bool isBinary = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | |
System.Boolean | isBinary |
Returns
Type | Description |
---|---|
Mat |
Remarks
This function has the same limitations as createTorchImporter().
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.
Declaration
public static void ResetMyriadDevice()
ShrinkCaffeModel(String, String, Nullable<IEnumerable<String>>)
Convert all weights of Caffe network to half precision floating point.
Declaration
public static void ShrinkCaffeModel(string src, string dst, IEnumerable<string>? layersTypes = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | src | Path to origin model from Caffe framework contains single
precision floating point weights(usually has |
System.String | dst | Path to destination model with updated weights. |
System.Nullable<IEnumerable<System.String>> | layersTypes | Set of layers types which parameters will be converted. By default, converts only Convolutional and Fully-Connected layers' weights. |
Remarks
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(String, String)
Create a text representation for a binary network stored in protocol buffer format.
Declaration
public static void WriteTextGraph(string model, string output)
Parameters
Type | Name | Description |
---|---|---|
System.String | model | A path to binary network. |
System.String | output | A path to output text file to be created. |