OpenCV for Unity
2.6.0
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.9.0/index.html ) for the details of the argument of the method.

The class implements KNearest Neighbors model. More...
Public Member Functions  
int  getDefaultK () 
void  setDefaultK (int val) 
bool  getIsClassifier () 
void  setIsClassifier (bool val) 
int  getEmax () 
void  setEmax (int val) 
int  getAlgorithmType () 
void  setAlgorithmType (int val) 
float  findNearest (Mat samples, int k, Mat results, Mat neighborResponses, Mat dist) 
Finds the neighbors and predicts responses for input vectors. More...  
float  findNearest (Mat samples, int k, Mat results, Mat neighborResponses) 
Finds the neighbors and predicts responses for input vectors. More...  
float  findNearest (Mat samples, int k, Mat results) 
Finds the neighbors and predicts responses for input vectors. More...  
Public Member Functions inherited from OpenCVForUnity.MlModule.StatModel  
int  getVarCount () 
Returns the number of variables in training samples. More...  
override bool  empty () 
Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. More...  
bool  isTrained () 
Returns true if the model is trained. More...  
bool  isClassifier () 
Returns true if the model is classifier. More...  
bool  train (TrainData trainData, int flags) 
Trains the statistical model. More...  
bool  train (TrainData trainData) 
Trains the statistical model. More...  
bool  train (Mat samples, int layout, Mat responses) 
Trains the statistical model. More...  
float  calcError (TrainData data, bool test, Mat resp) 
Computes error on the training or test dataset. More...  
virtual float  predict (Mat samples, Mat results, int flags) 
Predicts response(s) for the provided sample(s) More...  
virtual float  predict (Mat samples, Mat results) 
Predicts response(s) for the provided sample(s) More...  
virtual float  predict (Mat samples) 
Predicts response(s) for the provided sample(s) More...  
Public Member Functions inherited from OpenCVForUnity.CoreModule.Algorithm  
IntPtr  getNativeObjAddr () 
virtual void  clear () 
Clears the algorithm state. More...  
void  save (string filename) 
virtual string  getDefaultName () 
Public Member Functions inherited from OpenCVForUnity.DisposableObject  
void  Dispose () 
void  ThrowIfDisposed () 
Static Public Member Functions  
static new KNearest  __fromPtr__ (IntPtr addr) 
static KNearest  create () 
Creates the empty model. More...  
static KNearest  load (string filepath) 
Loads and creates a serialized knearest from a file. More...  
Static Public Member Functions inherited from OpenCVForUnity.MlModule.StatModel  
static new StatModel  __fromPtr__ (IntPtr addr) 
Static Public Member Functions inherited from OpenCVForUnity.CoreModule.Algorithm  
static Algorithm  __fromPtr__ (IntPtr addr) 
Static Public Member Functions inherited from OpenCVForUnity.DisposableObject  
static IntPtr  ThrowIfNullIntPtr (IntPtr ptr) 
Public Attributes  
const int  BRUTE_FORCE = 1 
const int  KDTREE = 2 
Public Attributes inherited from OpenCVForUnity.MlModule.StatModel  
const int  UPDATE_MODEL = 1 
const int  RAW_OUTPUT = 1 
const int  COMPRESSED_INPUT = 2 
const int  PREPROCESSED_INPUT = 4 
Protected Member Functions  
override void  Dispose (bool disposing) 
Protected Member Functions inherited from OpenCVForUnity.MlModule.StatModel  
override void  Dispose (bool disposing) 
Protected Member Functions inherited from OpenCVForUnity.DisposableOpenCVObject  
DisposableOpenCVObject ()  
DisposableOpenCVObject (IntPtr ptr)  
DisposableOpenCVObject (bool isEnabledDispose)  
DisposableOpenCVObject (IntPtr ptr, bool isEnabledDispose)  
Protected Member Functions inherited from OpenCVForUnity.DisposableObject  
DisposableObject ()  
DisposableObject (bool isEnabledDispose)  
Additional Inherited Members  
Properties inherited from OpenCVForUnity.DisposableObject  
bool  IsDisposed [get, protected set] 
bool  IsEnabledDispose [get, set] 
The class implements KNearest Neighbors model.

static 

static 
Creates the empty model.
The static method creates empty KNearest classifier. It should be then trained using StatModel::train method.

protectedvirtual 
Reimplemented from OpenCVForUnity.CoreModule.Algorithm.
float OpenCVForUnity.MlModule.KNearest.findNearest  (  Mat  samples, 
int  k,  
Mat  results,  
Mat  neighborResponses,  
Mat  dist  
) 
Finds the neighbors and predicts responses for input vectors.
samples  Input samples stored by rows. It is a singleprecision floatingpoint matrix of <number_of_samples> * k size. 
k  Number of used nearest neighbors. Should be greater than 1. 
results  Vector with results of prediction (regression or classification) for each input sample. It is a singleprecision floatingpoint vector with <number_of_samples> elements. 
neighborResponses  Optional output values for corresponding neighbors. It is a single precision floatingpoint matrix of <number_of_samples> * k size. 
dist  Optional output distances from the input vectors to the corresponding neighbors. It is a singleprecision floatingpoint matrix of <number_of_samples> * k size. 
For each input vector (a row of the matrix samples), the method finds the k nearest neighbors. In case of regression, the predicted result is a mean value of the particular vector's neighbor responses. In case of classification, the class is determined by voting.
For each input vector, the neighbors are sorted by their distances to the vector.
In case of C++ interface you can use output pointers to empty matrices and the function will allocate memory itself.
If only a single input vector is passed, all output matrices are optional and the predicted value is returned by the method.
The function is parallelized with the TBB library.
float OpenCVForUnity.MlModule.KNearest.findNearest  (  Mat  samples, 
int  k,  
Mat  results,  
Mat  neighborResponses  
) 
Finds the neighbors and predicts responses for input vectors.
samples  Input samples stored by rows. It is a singleprecision floatingpoint matrix of <number_of_samples> * k size. 
k  Number of used nearest neighbors. Should be greater than 1. 
results  Vector with results of prediction (regression or classification) for each input sample. It is a singleprecision floatingpoint vector with <number_of_samples> elements. 
neighborResponses  Optional output values for corresponding neighbors. It is a single precision floatingpoint matrix of <number_of_samples> * k size. 
dist  Optional output distances from the input vectors to the corresponding neighbors. It is a singleprecision floatingpoint matrix of <number_of_samples> * k size. 
For each input vector (a row of the matrix samples), the method finds the k nearest neighbors. In case of regression, the predicted result is a mean value of the particular vector's neighbor responses. In case of classification, the class is determined by voting.
For each input vector, the neighbors are sorted by their distances to the vector.
In case of C++ interface you can use output pointers to empty matrices and the function will allocate memory itself.
If only a single input vector is passed, all output matrices are optional and the predicted value is returned by the method.
The function is parallelized with the TBB library.
Finds the neighbors and predicts responses for input vectors.
samples  Input samples stored by rows. It is a singleprecision floatingpoint matrix of <number_of_samples> * k size. 
k  Number of used nearest neighbors. Should be greater than 1. 
results  Vector with results of prediction (regression or classification) for each input sample. It is a singleprecision floatingpoint vector with <number_of_samples> elements. 
neighborResponses  Optional output values for corresponding neighbors. It is a single precision floatingpoint matrix of <number_of_samples> * k size. 
dist  Optional output distances from the input vectors to the corresponding neighbors. It is a singleprecision floatingpoint matrix of <number_of_samples> * k size. 
For each input vector (a row of the matrix samples), the method finds the k nearest neighbors. In case of regression, the predicted result is a mean value of the particular vector's neighbor responses. In case of classification, the class is determined by voting.
For each input vector, the neighbors are sorted by their distances to the vector.
In case of C++ interface you can use output pointers to empty matrices and the function will allocate memory itself.
If only a single input vector is passed, all output matrices are optional and the predicted value is returned by the method.
The function is parallelized with the TBB library.
int OpenCVForUnity.MlModule.KNearest.getAlgorithmType  (  ) 
int OpenCVForUnity.MlModule.KNearest.getDefaultK  (  ) 
int OpenCVForUnity.MlModule.KNearest.getEmax  (  ) 
bool OpenCVForUnity.MlModule.KNearest.getIsClassifier  (  ) 

static 
Loads and creates a serialized knearest from a file.
Use KNearest::save to serialize and store an KNearest to disk. Load the KNearest from this file again, by calling this function with the path to the file.
filepath  path to serialized KNearest 
void OpenCVForUnity.MlModule.KNearest.setAlgorithmType  (  int  val  ) 
void OpenCVForUnity.MlModule.KNearest.setDefaultK  (  int  val  ) 
void OpenCVForUnity.MlModule.KNearest.setEmax  (  int  val  ) 
void OpenCVForUnity.MlModule.KNearest.setIsClassifier  (  bool  val  ) 
const int OpenCVForUnity.MlModule.KNearest.BRUTE_FORCE = 1 
const int OpenCVForUnity.MlModule.KNearest.KDTREE = 2 