Class Model
- Namespace
- OpenCvSharp.Dnn
- Assembly
- OpenCvSharp.dll
This class is presented high-level API for neural networks. It allows to set params for preprocessing input image. It creates net from file with trained weights and config, sets preprocessing input and runs forward pass.
public class Model : CvObject, IDisposable
- Inheritance
-
Model
- Implements
- Derived
- Inherited Members
Constructors
Model()
For derived classes that construct the native object themselves.
protected Model()
Model(Net)
Create model from deep learning network.
public Model(Net network)
Parameters
networkNetNet object.
Model(string, string?)
Create model from deep learning network represented in one of the supported formats. An order of @p model and @p config arguments does not matter.
public Model(string model, string? config = null)
Parameters
modelstringBinary file contains trained weights.
configstringText file contains network configuration.
Methods
EnableWinograd(bool)
Enables or disables the Winograd convolution optimization.
public void EnableWinograd(bool useWinograd)
Parameters
useWinogradbooltrue to enable, false to disable.
Predict(InputArray)
Given the @p input frame, create input blob, run net and return the output @p blobs.
public Mat[] Predict(InputArray frame)
Parameters
frameInputArrayThe input image.
Returns
- Mat[]
Allocated output blobs, which will store results of the computation.
SetHandle(nint, Func<nint, ExceptionStatus>)
Sets the underlying native handle together with the correct destructor.
protected void SetHandle(nint p, Func<nint, ExceptionStatus> deleter)
Parameters
pnintnative pointer
deleterFunc<nint, ExceptionStatus>native destructor for the concrete model type
SetInputCrop(bool)
Set flag crop for frame.
public void SetInputCrop(bool crop)
Parameters
cropboolFlag which indicates whether image will be cropped after resize or not.
SetInputMean(Scalar)
Set mean value for frame.
public void SetInputMean(Scalar mean)
Parameters
meanScalarScalar with mean values which are subtracted from channels.
SetInputParams(double, Size?, Scalar?, bool, bool)
Set preprocessing parameters for frame.
public void SetInputParams(double scale = 1, Size? size = null, Scalar? mean = null, bool swapRB = false, bool crop = false)
Parameters
scaledoubleMultiplier for frame values.
sizeSize?New input size.
meanScalar?Scalar with mean values which are subtracted from channels.
swapRBboolFlag which indicates that swap first and last channels.
cropboolFlag which indicates whether image will be cropped after resize or not.
SetInputScale(Scalar)
Set scalefactor value for frame.
public void SetInputScale(Scalar scale)
Parameters
scaleScalarMultiplier for frame values.
SetInputSize(Size)
Set input size for frame.
public void SetInputSize(Size size)
Parameters
sizeSizeNew input size.
Remarks
If shape of the new blob less than 0, then frame size not change.
SetInputSize(int, int)
Set input size for frame.
public void SetInputSize(int width, int height)
Parameters
SetInputSwapRB(bool)
Set flag swapRB for frame.
public void SetInputSwapRB(bool swapRB)
Parameters
swapRBboolFlag which indicates that swap first and last channels.
SetOutputNames(IEnumerable<string>)
Set output names for frame.
public void SetOutputNames(IEnumerable<string> outNames)
Parameters
outNamesIEnumerable<string>Names for output layers.
SetPreferableBackend(Backend)
Ask network to use specific computation backend where it supported.
public void SetPreferableBackend(Backend backendId)
Parameters
backendIdBackendbackend identifier.
SetPreferableTarget(Target)
Ask network to make computations on specific target device.
public void SetPreferableTarget(Target targetId)
Parameters
targetIdTargettarget identifier.