OpenCV for Unity 2.6.4
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.10.0/index.html ) for the details of the argument of the method.
Loading...
Searching...
No Matches
OpenCVForUnity.MlModule.TrainData Class Reference

Class encapsulating training data. More...

Public Member Functions

int getCatCount (int vi)
 
Mat getCatMap ()
 
Mat getCatOfs ()
 
Mat getClassLabels ()
 Returns the vector of class labels.
 
Mat getDefaultSubstValues ()
 
int getLayout ()
 
Mat getMissing ()
 
int getNAllVars ()
 
void getNames (List< string > names)
 Returns vector of symbolic names captured in loadFromCSV()
 
IntPtr getNativeObjAddr ()
 
Mat getNormCatResponses ()
 
int getNSamples ()
 
int getNTestSamples ()
 
int getNTrainSamples ()
 
int getNVars ()
 
Mat getResponses ()
 
int getResponseType ()
 
void getSample (Mat varIdx, int sidx, float buf)
 
Mat getSamples ()
 
Mat getSampleWeights ()
 
Mat getTestNormCatResponses ()
 
Mat getTestResponses ()
 
Mat getTestSampleIdx ()
 
Mat getTestSamples ()
 Returns matrix of test samples.
 
Mat getTestSampleWeights ()
 
Mat getTrainNormCatResponses ()
 Returns the vector of normalized categorical responses.
 
Mat getTrainResponses ()
 Returns the vector of responses.
 
Mat getTrainSampleIdx ()
 
Mat getTrainSamples ()
 Returns matrix of train samples.
 
Mat getTrainSamples (int layout)
 Returns matrix of train samples.
 
Mat getTrainSamples (int layout, bool compressSamples)
 Returns matrix of train samples.
 
Mat getTrainSamples (int layout, bool compressSamples, bool compressVars)
 Returns matrix of train samples.
 
Mat getTrainSampleWeights ()
 
void getValues (int vi, Mat sidx, float values)
 
Mat getVarIdx ()
 
Mat getVarSymbolFlags ()
 
Mat getVarType ()
 
void setTrainTestSplit (int count)
 Splits the training data into the training and test parts.
 
void setTrainTestSplit (int count, bool shuffle)
 Splits the training data into the training and test parts.
 
void setTrainTestSplitRatio (double ratio)
 Splits the training data into the training and test parts.
 
void setTrainTestSplitRatio (double ratio, bool shuffle)
 Splits the training data into the training and test parts.
 
void shuffleTrainTest ()
 
- Public Member Functions inherited from OpenCVForUnity.DisposableObject
void Dispose ()
 
void ThrowIfDisposed ()
 

Static Public Member Functions

static TrainData __fromPtr__ (IntPtr addr)
 
static TrainData create (Mat samples, int layout, Mat responses)
 Creates training data from in-memory arrays.
 
static TrainData create (Mat samples, int layout, Mat responses, Mat varIdx)
 Creates training data from in-memory arrays.
 
static TrainData create (Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx)
 Creates training data from in-memory arrays.
 
static TrainData create (Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx, Mat sampleWeights)
 Creates training data from in-memory arrays.
 
static TrainData create (Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx, Mat sampleWeights, Mat varType)
 Creates training data from in-memory arrays.
 
static Mat getSubMatrix (Mat matrix, Mat idx, int layout)
 Extract from matrix rows/cols specified by passed indexes.
 
static Mat getSubVector (Mat vec, Mat idx)
 Extract from 1D vector elements specified by passed indexes.
 
- Static Public Member Functions inherited from OpenCVForUnity.DisposableObject
static IntPtr ThrowIfNullIntPtr (IntPtr ptr)
 

Protected Member Functions

override void Dispose (bool disposing)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableOpenCVObject
 DisposableOpenCVObject ()
 
 DisposableOpenCVObject (bool isEnabledDispose)
 
 DisposableOpenCVObject (IntPtr ptr)
 
 DisposableOpenCVObject (IntPtr ptr, bool isEnabledDispose)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableObject
 DisposableObject ()
 
 DisposableObject (bool isEnabledDispose)
 

Additional Inherited Members

- Package Attributes inherited from OpenCVForUnity.DisposableOpenCVObject
- Properties inherited from OpenCVForUnity.DisposableObject
bool IsDisposed [get, protected set]
 
bool IsEnabledDispose [get, set]
 

Detailed Description

Class encapsulating training data.

Please note that the class only specifies the interface of training data, but not implementation. All the statistical model classes in ml module accepts Ptr<TrainData> as parameter. In other words, you can create your own class derived from TrainData and pass smart pointer to the instance of this class into StatModel.train.

See also
ml_intro_data

Member Function Documentation

◆ __fromPtr__()

static TrainData OpenCVForUnity.MlModule.TrainData.__fromPtr__ ( IntPtr addr)
static

◆ create() [1/5]

static TrainData OpenCVForUnity.MlModule.TrainData.create ( Mat samples,
int layout,
Mat responses )
static

Creates training data from in-memory arrays.

Parameters
samplesmatrix of samples. It should have CV_32F type.
layoutsee ml::SampleTypes.
responsesmatrix of responses. If the responses are scalar, they should be stored as a single row or as a single column. The matrix should have type CV_32F or CV_32S (in the former case the responses are considered as ordered by default; in the latter case - as categorical)
varIdxvector specifying which variables to use for training. It can be an integer vector (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of active variables.
sampleIdxvector specifying which samples to use for training. It can be an integer vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples.
sampleWeightsoptional vector with weights for each sample. It should have CV_32F type.
varTypeoptional vector of type CV_8U and size &lt;number_of_variables_in_samples&gt; + / &lt;number_of_variables_in_responses&gt;, containing types of each input and output variable. See ml::VariableTypes.

◆ create() [2/5]

static TrainData OpenCVForUnity.MlModule.TrainData.create ( Mat samples,
int layout,
Mat responses,
Mat varIdx )
static

Creates training data from in-memory arrays.

Parameters
samplesmatrix of samples. It should have CV_32F type.
layoutsee ml::SampleTypes.
responsesmatrix of responses. If the responses are scalar, they should be stored as a single row or as a single column. The matrix should have type CV_32F or CV_32S (in the former case the responses are considered as ordered by default; in the latter case - as categorical)
varIdxvector specifying which variables to use for training. It can be an integer vector (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of active variables.
sampleIdxvector specifying which samples to use for training. It can be an integer vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples.
sampleWeightsoptional vector with weights for each sample. It should have CV_32F type.
varTypeoptional vector of type CV_8U and size &lt;number_of_variables_in_samples&gt; + / &lt;number_of_variables_in_responses&gt;, containing types of each input and output variable. See ml::VariableTypes.

◆ create() [3/5]

static TrainData OpenCVForUnity.MlModule.TrainData.create ( Mat samples,
int layout,
Mat responses,
Mat varIdx,
Mat sampleIdx )
static

Creates training data from in-memory arrays.

Parameters
samplesmatrix of samples. It should have CV_32F type.
layoutsee ml::SampleTypes.
responsesmatrix of responses. If the responses are scalar, they should be stored as a single row or as a single column. The matrix should have type CV_32F or CV_32S (in the former case the responses are considered as ordered by default; in the latter case - as categorical)
varIdxvector specifying which variables to use for training. It can be an integer vector (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of active variables.
sampleIdxvector specifying which samples to use for training. It can be an integer vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples.
sampleWeightsoptional vector with weights for each sample. It should have CV_32F type.
varTypeoptional vector of type CV_8U and size &lt;number_of_variables_in_samples&gt; + / &lt;number_of_variables_in_responses&gt;, containing types of each input and output variable. See ml::VariableTypes.

◆ create() [4/5]

static TrainData OpenCVForUnity.MlModule.TrainData.create ( Mat samples,
int layout,
Mat responses,
Mat varIdx,
Mat sampleIdx,
Mat sampleWeights )
static

Creates training data from in-memory arrays.

Parameters
samplesmatrix of samples. It should have CV_32F type.
layoutsee ml::SampleTypes.
responsesmatrix of responses. If the responses are scalar, they should be stored as a single row or as a single column. The matrix should have type CV_32F or CV_32S (in the former case the responses are considered as ordered by default; in the latter case - as categorical)
varIdxvector specifying which variables to use for training. It can be an integer vector (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of active variables.
sampleIdxvector specifying which samples to use for training. It can be an integer vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples.
sampleWeightsoptional vector with weights for each sample. It should have CV_32F type.
varTypeoptional vector of type CV_8U and size &lt;number_of_variables_in_samples&gt; + / &lt;number_of_variables_in_responses&gt;, containing types of each input and output variable. See ml::VariableTypes.

◆ create() [5/5]

static TrainData OpenCVForUnity.MlModule.TrainData.create ( Mat samples,
int layout,
Mat responses,
Mat varIdx,
Mat sampleIdx,
Mat sampleWeights,
Mat varType )
static

Creates training data from in-memory arrays.

Parameters
samplesmatrix of samples. It should have CV_32F type.
layoutsee ml::SampleTypes.
responsesmatrix of responses. If the responses are scalar, they should be stored as a single row or as a single column. The matrix should have type CV_32F or CV_32S (in the former case the responses are considered as ordered by default; in the latter case - as categorical)
varIdxvector specifying which variables to use for training. It can be an integer vector (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of active variables.
sampleIdxvector specifying which samples to use for training. It can be an integer vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples.
sampleWeightsoptional vector with weights for each sample. It should have CV_32F type.
varTypeoptional vector of type CV_8U and size &lt;number_of_variables_in_samples&gt; + / &lt;number_of_variables_in_responses&gt;, containing types of each input and output variable. See ml::VariableTypes.

◆ Dispose()

override void OpenCVForUnity.MlModule.TrainData.Dispose ( bool disposing)
protectedvirtual

◆ getCatCount()

int OpenCVForUnity.MlModule.TrainData.getCatCount ( int vi)

◆ getCatMap()

Mat OpenCVForUnity.MlModule.TrainData.getCatMap ( )

◆ getCatOfs()

Mat OpenCVForUnity.MlModule.TrainData.getCatOfs ( )

◆ getClassLabels()

Mat OpenCVForUnity.MlModule.TrainData.getClassLabels ( )

Returns the vector of class labels.

The function returns vector of unique labels occurred in the responses.

◆ getDefaultSubstValues()

Mat OpenCVForUnity.MlModule.TrainData.getDefaultSubstValues ( )

◆ getLayout()

int OpenCVForUnity.MlModule.TrainData.getLayout ( )

◆ getMissing()

Mat OpenCVForUnity.MlModule.TrainData.getMissing ( )

◆ getNAllVars()

int OpenCVForUnity.MlModule.TrainData.getNAllVars ( )

◆ getNames()

void OpenCVForUnity.MlModule.TrainData.getNames ( List< string > names)

Returns vector of symbolic names captured in loadFromCSV()

◆ getNativeObjAddr()

IntPtr OpenCVForUnity.MlModule.TrainData.getNativeObjAddr ( )

◆ getNormCatResponses()

Mat OpenCVForUnity.MlModule.TrainData.getNormCatResponses ( )

◆ getNSamples()

int OpenCVForUnity.MlModule.TrainData.getNSamples ( )

◆ getNTestSamples()

int OpenCVForUnity.MlModule.TrainData.getNTestSamples ( )

◆ getNTrainSamples()

int OpenCVForUnity.MlModule.TrainData.getNTrainSamples ( )

◆ getNVars()

int OpenCVForUnity.MlModule.TrainData.getNVars ( )

◆ getResponses()

Mat OpenCVForUnity.MlModule.TrainData.getResponses ( )

◆ getResponseType()

int OpenCVForUnity.MlModule.TrainData.getResponseType ( )

◆ getSample()

void OpenCVForUnity.MlModule.TrainData.getSample ( Mat varIdx,
int sidx,
float buf )

◆ getSamples()

Mat OpenCVForUnity.MlModule.TrainData.getSamples ( )

◆ getSampleWeights()

Mat OpenCVForUnity.MlModule.TrainData.getSampleWeights ( )

◆ getSubMatrix()

static Mat OpenCVForUnity.MlModule.TrainData.getSubMatrix ( Mat matrix,
Mat idx,
int layout )
static

Extract from matrix rows/cols specified by passed indexes.

Parameters
matrixinput matrix (supported types: CV_32S, CV_32F, CV_64F)
idx1D index vector
layoutspecifies to extract rows (cv::ml::ROW_SAMPLES) or to extract columns (cv::ml::COL_SAMPLES)

◆ getSubVector()

static Mat OpenCVForUnity.MlModule.TrainData.getSubVector ( Mat vec,
Mat idx )
static

Extract from 1D vector elements specified by passed indexes.

Parameters
vecinput vector (supported types: CV_32S, CV_32F, CV_64F)
idx1D index vector

◆ getTestNormCatResponses()

Mat OpenCVForUnity.MlModule.TrainData.getTestNormCatResponses ( )

◆ getTestResponses()

Mat OpenCVForUnity.MlModule.TrainData.getTestResponses ( )

◆ getTestSampleIdx()

Mat OpenCVForUnity.MlModule.TrainData.getTestSampleIdx ( )

◆ getTestSamples()

Mat OpenCVForUnity.MlModule.TrainData.getTestSamples ( )

Returns matrix of test samples.

◆ getTestSampleWeights()

Mat OpenCVForUnity.MlModule.TrainData.getTestSampleWeights ( )

◆ getTrainNormCatResponses()

Mat OpenCVForUnity.MlModule.TrainData.getTrainNormCatResponses ( )

Returns the vector of normalized categorical responses.

The function returns vector of responses. Each response is integer from 0 to &lt;number of / classes&gt;-1. The actual label value can be retrieved then from the class label vector, see TrainData.getClassLabels.

◆ getTrainResponses()

Mat OpenCVForUnity.MlModule.TrainData.getTrainResponses ( )

Returns the vector of responses.

The function returns ordered or the original categorical responses. Usually it's used in regression algorithms.

◆ getTrainSampleIdx()

Mat OpenCVForUnity.MlModule.TrainData.getTrainSampleIdx ( )

◆ getTrainSamples() [1/4]

Mat OpenCVForUnity.MlModule.TrainData.getTrainSamples ( )

Returns matrix of train samples.

Parameters
layoutThe requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
compressSamplesif true, the function returns only the training samples (specified by sampleIdx)
compressVarsif true, the function returns the shorter training samples, containing only the active variables.

In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).

◆ getTrainSamples() [2/4]

Mat OpenCVForUnity.MlModule.TrainData.getTrainSamples ( int layout)

Returns matrix of train samples.

Parameters
layoutThe requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
compressSamplesif true, the function returns only the training samples (specified by sampleIdx)
compressVarsif true, the function returns the shorter training samples, containing only the active variables.

In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).

◆ getTrainSamples() [3/4]

Mat OpenCVForUnity.MlModule.TrainData.getTrainSamples ( int layout,
bool compressSamples )

Returns matrix of train samples.

Parameters
layoutThe requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
compressSamplesif true, the function returns only the training samples (specified by sampleIdx)
compressVarsif true, the function returns the shorter training samples, containing only the active variables.

In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).

◆ getTrainSamples() [4/4]

Mat OpenCVForUnity.MlModule.TrainData.getTrainSamples ( int layout,
bool compressSamples,
bool compressVars )

Returns matrix of train samples.

Parameters
layoutThe requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
compressSamplesif true, the function returns only the training samples (specified by sampleIdx)
compressVarsif true, the function returns the shorter training samples, containing only the active variables.

In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).

◆ getTrainSampleWeights()

Mat OpenCVForUnity.MlModule.TrainData.getTrainSampleWeights ( )

◆ getValues()

void OpenCVForUnity.MlModule.TrainData.getValues ( int vi,
Mat sidx,
float values )

◆ getVarIdx()

Mat OpenCVForUnity.MlModule.TrainData.getVarIdx ( )

◆ getVarSymbolFlags()

Mat OpenCVForUnity.MlModule.TrainData.getVarSymbolFlags ( )

◆ getVarType()

Mat OpenCVForUnity.MlModule.TrainData.getVarType ( )

◆ setTrainTestSplit() [1/2]

void OpenCVForUnity.MlModule.TrainData.setTrainTestSplit ( int count)

Splits the training data into the training and test parts.

See also
TrainData.setTrainTestSplitRatio

◆ setTrainTestSplit() [2/2]

void OpenCVForUnity.MlModule.TrainData.setTrainTestSplit ( int count,
bool shuffle )

Splits the training data into the training and test parts.

See also
TrainData.setTrainTestSplitRatio

◆ setTrainTestSplitRatio() [1/2]

void OpenCVForUnity.MlModule.TrainData.setTrainTestSplitRatio ( double ratio)

Splits the training data into the training and test parts.

The function selects a subset of specified relative size and then returns it as the training set. If the function is not called, all the data is used for training. Please, note that for each of TrainData::getTrain* there is corresponding TrainData::getTest*, so that the test subset can be retrieved and processed as well.

See also
TrainData.setTrainTestSplit

◆ setTrainTestSplitRatio() [2/2]

void OpenCVForUnity.MlModule.TrainData.setTrainTestSplitRatio ( double ratio,
bool shuffle )

Splits the training data into the training and test parts.

The function selects a subset of specified relative size and then returns it as the training set. If the function is not called, all the data is used for training. Please, note that for each of TrainData::getTrain* there is corresponding TrainData::getTest*, so that the test subset can be retrieved and processed as well.

See also
TrainData.setTrainTestSplit

◆ shuffleTrainTest()

void OpenCVForUnity.MlModule.TrainData.shuffleTrainTest ( )

The documentation for this class was generated from the following file: