@Namespace(value="cv::ml") public static class opencv_ml.KNearest extends opencv_ml.StatModel
\sa \ref ml_intro_knn
| 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 |
|---|
KNearest(org.bytedeco.javacpp.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.GpuMat samples,
int k,
opencv_core.GpuMat results) |
float |
findNearest(opencv_core.GpuMat samples,
int k,
opencv_core.GpuMat results,
opencv_core.GpuMat neighborResponses,
opencv_core.GpuMat dist) |
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.
|
float |
findNearest(opencv_core.UMat samples,
int k,
opencv_core.UMat results) |
float |
findNearest(opencv_core.UMat samples,
int k,
opencv_core.UMat results,
opencv_core.UMat neighborResponses,
opencv_core.UMat dist) |
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, calcError, calcError, empty, getVarCount, isClassifier, isTrained, predict, predict, predict, predict, predict, predict, train, train, 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, write, write, writeaddress, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, hashCode, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, parseBytes, physicalBytes, position, put, realloc, setNull, sizeof, toString, totalBytes, totalPhysicalBytes, withDeallocator, zeropublic static final int BRUTE_FORCE
public static final int KDTREE
public KNearest(org.bytedeco.javacpp.Pointer p)
Pointer.Pointer(Pointer).public int getDefaultK()
setDefaultKpublic void setDefaultK(int val)
@Cast(value="bool") public boolean getIsClassifier()
setIsClassifierpublic 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::OutputArray(cv::noArray())")
opencv_core.Mat neighborResponses,
@ByVal(nullValue="cv::OutputArray(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)
public float findNearest(@ByVal
opencv_core.UMat samples,
int k,
@ByVal
opencv_core.UMat results,
@ByVal(nullValue="cv::OutputArray(cv::noArray())")
opencv_core.UMat neighborResponses,
@ByVal(nullValue="cv::OutputArray(cv::noArray())")
opencv_core.UMat dist)
public float findNearest(@ByVal
opencv_core.UMat samples,
int k,
@ByVal
opencv_core.UMat results)
public float findNearest(@ByVal
opencv_core.GpuMat samples,
int k,
@ByVal
opencv_core.GpuMat results,
@ByVal(nullValue="cv::OutputArray(cv::noArray())")
opencv_core.GpuMat neighborResponses,
@ByVal(nullValue="cv::OutputArray(cv::noArray())")
opencv_core.GpuMat dist)
public float findNearest(@ByVal
opencv_core.GpuMat samples,
int k,
@ByVal
opencv_core.GpuMat 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 © 2018. All rights reserved.