@Namespace(value="cv::ml") public static class opencv_ml.KNearest extends opencv_ml.StatModel
\sa \ref ml_intro_knn
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator| Modifier and Type | Field and Description |
|---|---|
static int |
BRUTE_FORCE
enum cv::ml::KNearest::Types
|
static int |
KDTREE
enum cv::ml::KNearest::Types
|
COMPRESSED_INPUT, PREPROCESSED_INPUT, RAW_OUTPUT, UPDATE_MODEL| Constructor and Description |
|---|
opencv_ml.KNearest(Pointer p)
Pointer cast constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static opencv_ml.KNearest |
create()
\brief Creates the empty model
|
float |
findNearest(opencv_core.Mat samples,
int k,
opencv_core.Mat results) |
float |
findNearest(opencv_core.Mat samples,
int k,
opencv_core.Mat results,
opencv_core.Mat neighborResponses,
opencv_core.Mat dist)
\brief Finds the neighbors and predicts responses for input vectors.
|
int |
getAlgorithmType() |
int |
getDefaultK() |
int |
getEmax() |
boolean |
getIsClassifier() |
void |
setAlgorithmType(int val)
\copybrief getAlgorithmType @see getAlgorithmType
|
void |
setDefaultK(int val)
\copybrief getDefaultK @see getDefaultK
|
void |
setEmax(int val)
\copybrief getEmax @see getEmax
|
void |
setIsClassifier(boolean val)
\copybrief getIsClassifier @see getIsClassifier
|
calcError, empty, getVarCount, isClassifier, isTrained, predict, predict, train, train, trainloadANN_MLP, loadANN_MLP, loadBoost, loadBoost, loadDTrees, loadDTrees, loadEM, loadEM, loadKNearest, loadKNearest, loadLogisticRegression, loadLogisticRegression, loadNormalBayesClassifier, loadNormalBayesClassifier, loadRTrees, loadRTrees, loadSVM, loadSVMclear, getDefaultName, position, read, save, save, writeaddress, asBuffer, asByteBuffer, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, hashCode, isNull, limit, limit, maxBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, position, put, setNull, sizeof, toString, totalBytes, withDeallocator, zeropublic static final int BRUTE_FORCE
public static final int KDTREE
public opencv_ml.KNearest(Pointer p)
Pointer.Pointer(Pointer).public int getDefaultK()
setDefaultKpublic void setDefaultK(int val)
public void setIsClassifier(@Cast(value="bool") boolean val)
public int getEmax()
setEmaxpublic void setEmax(int val)
public int getAlgorithmType()
setAlgorithmTypepublic void setAlgorithmType(int val)
public float findNearest(@ByVal opencv_core.Mat samples, int k, @ByVal opencv_core.Mat results, @ByVal(nullValue="cv::noArray()") opencv_core.Mat neighborResponses, @ByVal(nullValue="cv::noArray()") opencv_core.Mat dist)
samples - Input samples stored by rows. It is a single-precision floating-point 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 single-precision floating-point vector with <number_of_samples> elements.neighborResponses - Optional output values for corresponding neighbors. It is a single-
precision floating-point matrix of <number_of_samples> * k size.dist - Optional output distances from the input vectors to the corresponding neighbors. It
is a single-precision floating-point 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.
public float findNearest(@ByVal opencv_core.Mat samples, int k, @ByVal opencv_core.Mat results)
@opencv_core.Ptr public static opencv_ml.KNearest create()
The static method creates empty %KNearest classifier. It should be then trained using StatModel::train method.
Copyright © 2016. All rights reserved.