Table of Contents

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

network Net

Net 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

model string

Binary file contains trained weights.

config string

Text file contains network configuration.

Methods

EnableWinograd(bool)

Enables or disables the Winograd convolution optimization.

public void EnableWinograd(bool useWinograd)

Parameters

useWinograd bool

true 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

frame InputArray

The 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

p nint

native pointer

deleter Func<nint, ExceptionStatus>

native destructor for the concrete model type

SetInputCrop(bool)

Set flag crop for frame.

public void SetInputCrop(bool crop)

Parameters

crop bool

Flag which indicates whether image will be cropped after resize or not.

SetInputMean(Scalar)

Set mean value for frame.

public void SetInputMean(Scalar mean)

Parameters

mean Scalar

Scalar 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

scale double

Multiplier for frame values.

size Size?

New input size.

mean Scalar?

Scalar with mean values which are subtracted from channels.

swapRB bool

Flag which indicates that swap first and last channels.

crop bool

Flag which indicates whether image will be cropped after resize or not.

SetInputScale(Scalar)

Set scalefactor value for frame.

public void SetInputScale(Scalar scale)

Parameters

scale Scalar

Multiplier for frame values.

SetInputSize(Size)

Set input size for frame.

public void SetInputSize(Size size)

Parameters

size Size

New 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

width int

New input width.

height int

New input height.

SetInputSwapRB(bool)

Set flag swapRB for frame.

public void SetInputSwapRB(bool swapRB)

Parameters

swapRB bool

Flag which indicates that swap first and last channels.

SetOutputNames(IEnumerable<string>)

Set output names for frame.

public void SetOutputNames(IEnumerable<string> outNames)

Parameters

outNames IEnumerable<string>

Names for output layers.

SetPreferableBackend(Backend)

Ask network to use specific computation backend where it supported.

public void SetPreferableBackend(Backend backendId)

Parameters

backendId Backend

backend identifier.

SetPreferableTarget(Target)

Ask network to make computations on specific target device.

public void SetPreferableTarget(Target targetId)

Parameters

targetId Target

target identifier.