dnn_Model
import { dnn_Model } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods.
This class is presented high-level API for neural networks.
Model allows to set params for preprocessing input image. Model creates net from file with trained weights and config, sets preprocessing input and runs forward pass.
Constructors and members
static new
Create model from deep learning network represented in one of the supported formats.
An order of model and config arguments does not matter.
new(model: EmbindString, config: EmbindString): dnn_Model;2 available overloads
new(network: EmbindString): dnn_Model;new(model: EmbindString, config: EmbindString): dnn_Model;networkNet object.
modelBinary file contains trained weights.
configText file contains network configuration.
The dnn_Model result.
static from1
Create an owned dnn_Model instance with the supplied configuration.
This class is presented high-level API for neural networks.
from1(_0: dnn_Net): dnn_Model | null;_00 argument (dnn_Net).
The dnn_Model | null result.
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
setInputSize
Set input size for frame.
Note: If shape of the new blob less than 0, then frame size not change.
setInputSize(size: Size): dnn_Model;sizeNew input size.
The dnn_Model result.
setInputSize1
Set input size for frame.
Note: If shape of the new blob less than 0, then frame size not change.
setInputSize1(width: number, height: number): dnn_Model;widthNew input width.
heightNew input height.
The dnn_Model result.
setInputMean
Set mean value for frame.
setInputMean(mean: Scalar): dnn_Model;meanScalar with mean values which are subtracted from channels.
The dnn_Model result.
setInputScale
Set scalefactor value for frame.
setInputScale(scale: Scalar): dnn_Model;scaleMultiplier for frame values.
The dnn_Model result.
setInputCrop
Set flag crop for frame.
setInputCrop(crop: boolean): dnn_Model;cropFlag which indicates whether image will be cropped after resize or not.
The dnn_Model result.
setInputSwapRB
Set flag swapRB for frame.
setInputSwapRB(swapRB: boolean): dnn_Model;swapRBFlag which indicates that swap first and last channels.
The dnn_Model result.
setOutputNames
Set output names for frame.
setOutputNames(outNames: StringVector): dnn_Model;outNamesNames for output layers.
The dnn_Model result.
setInputParams
Set preprocessing parameters for frame.
setInputParams(scale: number, size: Size, mean: Scalar, swapRB: boolean, crop: boolean): void;6 available overloads
setInputParams(): void;setInputParams(scale: number): void;setInputParams(scale: number, size: Size): void;setInputParams(scale: number, size: Size, mean: Scalar): void;setInputParams(scale: number, size: Size, mean: Scalar, swapRB: boolean): void;setInputParams(scale: number, size: Size, mean: Scalar, swapRB: boolean, crop: boolean): void;scaleMultiplier for frame values.
sizeNew input size.
meanScalar with mean values which are subtracted from channels.
swapRBFlag which indicates that swap first and last channels.
cropFlag which indicates whether image will be cropped after resize or not. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )
predict
Given the input frame, create input blob, run net and return the output blobs.
predict(frame: Mat, outs: MatVector): void;frameThe input image.
outsOutput destination, filled by the native operation. Allocated output blobs, which will store results of the computation.
setPreferableBackend
============================== Net proxy methods ============================== Never expose methods with network implementation details, like:
- addLayer, addLayerToPrev, connect, setInputsNames, setInputShape, setParam, getParam
- getLayer*, getUnconnectedOutLayers, getUnconnectedOutLayersNames, getLayersShapes
- forward* methods, setInput See: Net::setPreferableBackend
setPreferableBackend(backendId: number): dnn_Model;backendIdbackend id argument (number).
The dnn_Model result.
setPreferableTarget
See: Net::setPreferableTarget
setPreferableTarget(targetId: number): dnn_Model;targetIdtarget id argument (number).
The dnn_Model result.
enableWinograd
See: Net::enableWinograd
enableWinograd(useWinograd: boolean): dnn_Model;useWinograduse winograd argument (boolean).
The dnn_Model result.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.