Class CvDnn
- Namespace
- OpenCvSharp.Dnn
- Assembly
- OpenCvSharp.dll
cv::dnn functions
public static class CvDnn
- Inheritance
-
CvDnn
- Inherited Members
Methods
BlobFromImage(Mat, double, Size, Scalar, bool, bool)
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.
public static Mat BlobFromImage(Mat image, double scaleFactor = 1, Size size = default, Scalar mean = default, bool swapRB = true, bool crop = true)
Parameters
imageMatinput image (with 1- or 3-channels).
scaleFactordoublemultiplier for @p image values.
sizeSizespatial size for output image
meanScalarscalar 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.
swapRBboolflag which indicates that swap first and last channels in 3-channel image is necessary.
cropboolflag which indicates whether image will be cropped after resize or not
Returns
- 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, bool, bool)
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.
public static Mat BlobFromImages(IEnumerable<Mat> images, double scaleFactor, Size size = default, Scalar mean = default, bool swapRB = true, bool crop = true)
Parameters
imagesIEnumerable<Mat>input images (all with 1- or 3-channels).
scaleFactordoublemultiplier for @p image values.
sizeSizespatial size for output image
meanScalarscalar 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.
swapRBboolflag which indicates that swap first and last channels in 3-channel image is necessary.
cropboolflag which indicates whether image will be cropped after resize or not
Returns
- 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<Rect2d>, IEnumerable<float>, float, float, out int[], float, int)
Performs non maximum suppression given boxes and corresponding scores.
public static void NMSBoxes(IEnumerable<Rect2d> bboxes, IEnumerable<float> scores, float scoreThreshold, float nmsThreshold, out int[] indices, float eta = 1, int topK = 0)
Parameters
bboxesIEnumerable<Rect2d>a set of bounding boxes to apply NMS.
scoresIEnumerable<float>a set of corresponding confidences.
scoreThresholdfloata threshold used to filter boxes by score.
nmsThresholdfloata threshold used in non maximum suppression.
indicesint[]the kept indices of bboxes after NMS.
etafloata coefficient in adaptive threshold formula
topKintif
>0, keep at most @p top_k picked indices.
NMSBoxes(IEnumerable<Rect>, IEnumerable<float>, float, float, out int[], float, int)
Performs non maximum suppression given boxes and corresponding scores.
public static void NMSBoxes(IEnumerable<Rect> bboxes, IEnumerable<float> scores, float scoreThreshold, float nmsThreshold, out int[] indices, float eta = 1, int topK = 0)
Parameters
bboxesIEnumerable<Rect>a set of bounding boxes to apply NMS.
scoresIEnumerable<float>a set of corresponding confidences.
scoreThresholdfloata threshold used to filter boxes by score.
nmsThresholdfloata threshold used in non maximum suppression.
indicesint[]the kept indices of bboxes after NMS.
etafloata coefficient in adaptive threshold formula
topKintif
>0, keep at most @p top_k picked indices.
NMSBoxes(IEnumerable<RotatedRect>, IEnumerable<float>, float, float, out int[], float, int)
Performs non maximum suppression given boxes and corresponding scores.
public static void NMSBoxes(IEnumerable<RotatedRect> bboxes, IEnumerable<float> scores, float scoreThreshold, float nmsThreshold, out int[] indices, float eta = 1, int topK = 0)
Parameters
bboxesIEnumerable<RotatedRect>a set of bounding boxes to apply NMS.
scoresIEnumerable<float>a set of corresponding confidences.
scoreThresholdfloata threshold used to filter boxes by score.
nmsThresholdfloata threshold used in non maximum suppression.
indicesint[]the kept indices of bboxes after NMS.
etafloata coefficient in adaptive threshold formula
topKintif
>0, keep at most @p top_k picked indices.
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,
public static Net ReadNet(string model, string config = "", string framework = "")
Parameters
modelstringBinary 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)configstringText 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)frameworkstringExplicit framework name tag to determine a format.
Returns
ReadNetFromCaffe(byte[], byte[]?)
Reads a network model stored in Caffe model files from memory.
public static Net? ReadNetFromCaffe(byte[] bufferProto, byte[]? bufferModel = null)
Parameters
bufferProtobyte[]buffer containing the content of the .prototxt file
bufferModelbyte[]buffer containing the content of the .caffemodel file
Returns
Remarks
This is shortcut consisting from createCaffeImporter and Net::populateNet calls.
ReadNetFromCaffe(Stream, Stream?)
Reads a network model stored in Caffe model files from Stream.
public static Net? ReadNetFromCaffe(Stream bufferProto, Stream? bufferModel = null)
Parameters
bufferProtoStreambuffer containing the content of the .prototxt file
bufferModelStreambuffer containing the content of the .caffemodel file
Returns
Remarks
This is shortcut consisting from createCaffeImporter and Net::populateNet calls.
ReadNetFromCaffe(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Reads a network model stored in Caffe model files from memory.
public static Net? ReadNetFromCaffe(ReadOnlySpan<byte> bufferProto, ReadOnlySpan<byte> bufferModel = default)
Parameters
bufferProtoReadOnlySpan<byte>buffer containing the content of the .prototxt file
bufferModelReadOnlySpan<byte>buffer containing the content of the .caffemodel file
Returns
Remarks
This is shortcut consisting from createCaffeImporter and Net::populateNet calls.
ReadNetFromCaffe(string, string?)
Reads a network model stored in Caffe model files.
public static Net? ReadNetFromCaffe(string prototxt, string? caffeModel = null)
Parameters
prototxtstringpath to the .prototxt file with text description of the network architecture.
caffeModelstringpath to the .caffemodel file with learned network.
Returns
Remarks
This is shortcut consisting from createCaffeImporter and Net::populateNet calls.
ReadNetFromDarknet(byte[], byte[]?)
Reads a network model stored in Darknet (https://pjreddie.com/darknet/) model files from memory.
public static Net? ReadNetFromDarknet(byte[] bufferCfg, byte[]? bufferModel = null)
Parameters
bufferCfgbyte[]A buffer contains a content of .cfg file with text description of the network architecture.
bufferModelbyte[]A buffer contains a content of .weights file with learned network.
Returns
Remarks
This is shortcut consisting from DarknetImporter and Net::populateNet calls.
ReadNetFromDarknet(Stream, Stream?)
Reads a network model stored in Darknet (https://pjreddie.com/darknet/) model files from stream.
public static Net? ReadNetFromDarknet(Stream bufferCfg, Stream? bufferModel = null)
Parameters
bufferCfgStreamA buffer contains a content of .cfg file with text description of the network architecture.
bufferModelStreamA buffer contains a content of .weights file with learned network.
Returns
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.
public static Net? ReadNetFromDarknet(string cfgFile, string? darknetModel = null)
Parameters
cfgFilestringpath to the .cfg file with text description of the network architecture.
darknetModelstringpath to the .weights file with learned network.
Returns
- 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(byte[])
Reads a network model ONNX https://onnx.ai/ from memory
public static Net? ReadNetFromOnnx(byte[] onnxFileData)
Parameters
onnxFileDatabyte[]memory of the first byte of the buffer.
Returns
ReadNetFromOnnx(Stream)
Reads a network model ONNX https://onnx.ai/ from stream.
public static Net? ReadNetFromOnnx(Stream onnxFileStream)
Parameters
onnxFileStreamStreammemory of the first byte of the buffer.
Returns
ReadNetFromOnnx(ReadOnlySpan<byte>)
Reads a network model ONNX https://onnx.ai/ from memory
public static Net? ReadNetFromOnnx(ReadOnlySpan<byte> onnxFileData)
Parameters
onnxFileDataReadOnlySpan<byte>memory of the first byte of the buffer.
Returns
ReadNetFromOnnx(string)
Reads a network model ONNX https://onnx.ai/ from memory
public static Net? ReadNetFromOnnx(string onnxFile)
Parameters
onnxFilestring
Returns
ReadNetFromTensorflow(byte[], byte[]?)
Reads a network model stored in Tensorflow model file from memory.
public static Net? ReadNetFromTensorflow(byte[] bufferModel, byte[]? bufferConfig = null)
Parameters
bufferModelbyte[]buffer containing the content of the pb file
bufferConfigbyte[]buffer containing the content of the pbtxt file (optional)
Returns
Remarks
This is shortcut consisting from createTensorflowImporter and Net::populateNet calls.
ReadNetFromTensorflow(Stream, Stream?)
Reads a network model stored in Tensorflow model file from stream.
public static Net? ReadNetFromTensorflow(Stream bufferModel, Stream? bufferConfig = null)
Parameters
bufferModelStreambuffer containing the content of the pb file
bufferConfigStreambuffer containing the content of the pbtxt file (optional)
Returns
Remarks
This is shortcut consisting from createTensorflowImporter and Net::populateNet calls.
ReadNetFromTensorflow(string, string?)
Reads a network model stored in Tensorflow model file.
public static Net? ReadNetFromTensorflow(string model, string? config = null)
Parameters
modelstringpath to the .pb file with binary protobuf description of the network architecture
configstringpath to the .pbtxt file that contains text graph definition in protobuf format.
Returns
- 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, bool)
Reads a network model stored in Torch model file.
public static Net? ReadNetFromTorch(string model, bool isBinary = true)
Parameters
Returns
Remarks
This is shortcut consisting from createTorchImporter and Net::populateNet calls.
ReadTensorFromONNX(string)
Creates blob from .pb file.
public static Mat? ReadTensorFromONNX(string path)
Parameters
pathstringpath to the .pb file with input tensor.
Returns
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
Returns
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.
public static void ResetMyriadDevice()
ShrinkCaffeModel(string, string, IEnumerable<string>?)
Convert all weights of Caffe network to half precision floating point.
[SuppressMessage("Maintainability", "CA1508: Avoid dead conditional code")]
public static void ShrinkCaffeModel(string src, string dst, IEnumerable<string>? layersTypes = null)
Parameters
srcstringPath to origin model from Caffe framework contains single precision floating point weights(usually has
.caffemodelextension).dststringPath to destination model with updated weights.
layersTypesIEnumerable<string>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.
public static void WriteTextGraph(string model, string output)