Class Cv2.Dnn
- Namespace
- OpenCvSharp
- Assembly
- OpenCvSharp.dll
cv::dnn functions
public static class Cv2.Dnn
- Inheritance
-
Cv2.Dnn
- 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.
BlobFromImageWithParams(InputArray, Image2BlobParams?)
Creates 4-dimensional blob from image with given params. This function is an extension of BlobFromImage(Mat, double, Size, Scalar, bool, bool) to meet more image preprocess needs.
public static Mat BlobFromImageWithParams(InputArray image, Image2BlobParams? param = null)
Parameters
imageInputArrayinput image (all with 1-, 3- or 4-channels).
paramImage2BlobParamsparams with preprocessing parameters. If null, default params are used.
Returns
- Mat
4-dimensional Mat.
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.
BlobFromImagesWithParams(IEnumerable<Mat>, Image2BlobParams?)
Creates 4-dimensional blob from series of images with given params.
public static Mat BlobFromImagesWithParams(IEnumerable<Mat> images, Image2BlobParams? param = null)
Parameters
imagesIEnumerable<Mat>input images (all with 1-, 3- or 4-channels).
paramImage2BlobParamsparams with preprocessing parameters. If null, default params are used.
Returns
- Mat
4-dimensional Mat.
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
isDiagnosticsModeboolindicates whether diagnostic mode should be set.
GetAvailableBackends()
Returns the list of available (backend, target) pairs supported by this build.
public static (Backend Backend, Target Target)[] GetAvailableBackends()
Returns
GetAvailableTargets(Backend)
Returns the list of available computation targets for the given backend.
public static Target[] GetAvailableTargets(Backend backend)
Parameters
backendBackendbackend identifier.
Returns
- Target[]
available targets.
ImagesFromBlob(Mat)
Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure (std::vector<cv::Mat>).
public static Mat[] ImagesFromBlob(Mat blob)
Parameters
blobMat4 dimensional array (images, channels, height, width) in floating point precision (CV_32F) from which you would like to extract the images.
Returns
- Mat[]
array of 2D Mat containing the images extracted from the blob in floating point precision (CV_32F).
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.
NMSBoxesBatched(IEnumerable<Rect2d>, IEnumerable<float>, IEnumerable<int>, float, float, out int[], float, int)
Performs batched non maximum suppression on given boxes and corresponding scores across different classes.
public static void NMSBoxesBatched(IEnumerable<Rect2d> bboxes, IEnumerable<float> scores, IEnumerable<int> classIds, 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.
classIdsIEnumerable<int>a set of corresponding class ids. Ids are integer and usually start from 0.
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.
NMSBoxesBatched(IEnumerable<Rect>, IEnumerable<float>, IEnumerable<int>, float, float, out int[], float, int)
Performs batched non maximum suppression on given boxes and corresponding scores across different classes.
public static void NMSBoxesBatched(IEnumerable<Rect> bboxes, IEnumerable<float> scores, IEnumerable<int> classIds, 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.
classIdsIEnumerable<int>a set of corresponding class ids. Ids are integer and usually start from 0.
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, EngineType)
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 readNetFromTensorflow, @ref readNetFromONNX, or @ref readNetFromModelOptimizer. The Caffe, Darknet and Torch parsers were removed in OpenCV 5.
public static Net ReadNet(string model, string config = "", string framework = "", EngineType engine = EngineType.Auto)
Parameters
modelstringBinary file contains trained weights. The following file * extensions are expected for models from different frameworks: * *
*.pb(TensorFlow, https://www.tensorflow.org/) * **.onnx(ONNX, https://onnx.ai/) * **.bin(OpenVINO, https://software.intel.com/openvino-toolkit)configstringText file contains network configuration. It could be a * file with the following extensions: * *
*.pbtxt(TensorFlow, https://www.tensorflow.org/) * **.xml(OpenVINO, https://software.intel.com/openvino-toolkit)frameworkstringExplicit framework name tag to determine a format.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromONNX(byte[], EngineType)
Reads a network model ONNX https://onnx.ai/ from memory
public static Net? ReadNetFromONNX(byte[] onnxFileData, EngineType engine = EngineType.Auto)
Parameters
onnxFileDatabyte[]memory of the first byte of the buffer.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromONNX(Stream, EngineType)
Reads a network model ONNX https://onnx.ai/ from stream.
public static Net? ReadNetFromONNX(Stream onnxFileStream, EngineType engine = EngineType.Auto)
Parameters
onnxFileStreamStreammemory of the first byte of the buffer.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromONNX(ReadOnlySpan<byte>, EngineType)
Reads a network model ONNX https://onnx.ai/ from memory
public static Net? ReadNetFromONNX(ReadOnlySpan<byte> onnxFileData, EngineType engine = EngineType.Auto)
Parameters
onnxFileDataReadOnlySpan<byte>memory of the first byte of the buffer.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromONNX(string, EngineType)
Reads a network model ONNX https://onnx.ai/ from memory
public static Net? ReadNetFromONNX(string onnxFile, EngineType engine = EngineType.Auto)
Parameters
onnxFilestringengineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromTFLite(byte[], EngineType)
Reads a network model stored in TFLite framework's format from memory.
public static Net? ReadNetFromTFLite(byte[] bufferModel, EngineType engine = EngineType.Auto)
Parameters
bufferModelbyte[]buffer containing the content of the tflite file.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromTFLite(Stream, EngineType)
Reads a network model stored in TFLite framework's format from stream.
public static Net? ReadNetFromTFLite(Stream bufferModelStream, EngineType engine = EngineType.Auto)
Parameters
bufferModelStreamStreamstream containing the content of the tflite file.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromTFLite(ReadOnlySpan<byte>, EngineType)
Reads a network model stored in TFLite framework's format from memory.
public static Net? ReadNetFromTFLite(ReadOnlySpan<byte> bufferModel, EngineType engine = EngineType.Auto)
Parameters
bufferModelReadOnlySpan<byte>buffer containing the content of the tflite file.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromTFLite(string, EngineType)
Reads a network model stored in TFLite (https://www.tensorflow.org/lite) framework's format.
public static Net? ReadNetFromTFLite(string model, EngineType engine = EngineType.Auto)
Parameters
modelstringpath to the .tflite file with binary flatbuffers description of the network architecture.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
ReadNetFromTensorflow(byte[], byte[]?, EngineType)
Reads a network model stored in Tensorflow model file from memory.
public static Net? ReadNetFromTensorflow(byte[] bufferModel, byte[]? bufferConfig = null, EngineType engine = EngineType.Auto)
Parameters
bufferModelbyte[]buffer containing the content of the pb file
bufferConfigbyte[]buffer containing the content of the pbtxt file (optional)
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
Remarks
This is shortcut consisting from createTensorflowImporter and Net::populateNet calls.
ReadNetFromTensorflow(Stream, Stream?, EngineType)
Reads a network model stored in Tensorflow model file from stream.
public static Net? ReadNetFromTensorflow(Stream bufferModel, Stream? bufferConfig = null, EngineType engine = EngineType.Auto)
Parameters
bufferModelStreambuffer containing the content of the pb file
bufferConfigStreambuffer containing the content of the pbtxt file (optional)
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
Returns
Remarks
This is shortcut consisting from createTensorflowImporter and Net::populateNet calls.
ReadNetFromTensorflow(string, string?, EngineType)
Reads a network model stored in Tensorflow model file.
public static Net? ReadNetFromTensorflow(string model, string? config = null, EngineType engine = EngineType.Auto)
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.
engineEngineTypeDNN engine to use. Auto tries the new engine first and falls back to the classic one.
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.
ReadTensorFromONNX(string)
Creates blob from .pb file.
public static Mat? ReadTensorFromONNX(string path)
Parameters
pathstringpath to the .pb file with input tensor.
Returns
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()
SoftNMSBoxes(IEnumerable<Rect>, IEnumerable<float>, out float[], float, float, out int[], int, float, SoftNMSMethod)
Performs soft non maximum suppression given boxes and corresponding scores. Reference: https://arxiv.org/abs/1704.04503
public static void SoftNMSBoxes(IEnumerable<Rect> bboxes, IEnumerable<float> scores, out float[] updatedScores, float scoreThreshold, float nmsThreshold, out int[] indices, int topK = 0, float sigma = 0.5, SoftNMSMethod method = SoftNMSMethod.SOFTNMS_GAUSSIAN)
Parameters
bboxesIEnumerable<Rect>a set of bounding boxes to apply Soft NMS.
scoresIEnumerable<float>a set of corresponding confidences.
updatedScoresfloat[]a set of corresponding updated confidences.
scoreThresholdfloata threshold used to filter boxes by score.
nmsThresholdfloata threshold used in non maximum suppression.
indicesint[]the kept indices of bboxes after NMS.
topKintkeep at most @p top_k picked indices.
sigmafloatparameter of Gaussian weighting.
methodSoftNMSMethodGaussian 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)