@Namespace(value="cv::ml") @Properties(inherit=opencv_ml.class) public class KNearest extends StatModel
ml_intro_knn
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
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(Pointer p)
Pointer cast constructor.
|
Modifier and Type | Method and Description |
---|---|
static KNearest |
create()
\brief Creates the empty model
|
float |
findNearest(GpuMat samples,
int k,
GpuMat results) |
float |
findNearest(GpuMat samples,
int k,
GpuMat results,
GpuMat neighborResponses,
GpuMat dist) |
float |
findNearest(Mat samples,
int k,
Mat results) |
float |
findNearest(Mat samples,
int k,
Mat results,
Mat neighborResponses,
Mat dist)
\brief Finds the neighbors and predicts responses for input vectors.
|
float |
findNearest(UMat samples,
int k,
UMat results) |
float |
findNearest(UMat samples,
int k,
UMat results,
UMat neighborResponses,
UMat dist) |
int |
getAlgorithmType() |
int |
getDefaultK() |
int |
getEmax() |
boolean |
getIsClassifier() |
static KNearest |
load(BytePointer filepath)
\brief Loads and creates a serialized knearest from a file
Use KNearest::save to serialize and store an KNearest to disk.
|
static KNearest |
load(String filepath) |
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, train
loadANN_MLP, loadANN_MLP, loadBoost, loadBoost, loadDTrees, loadDTrees, loadEM, loadEM, loadKNearest, loadKNearest, loadLogisticRegression, loadLogisticRegression, loadNormalBayesClassifier, loadNormalBayesClassifier, loadRTrees, loadRTrees, loadSVM, loadSVM
clear, getDefaultName, position, read, save, save, write, write, write
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, hashCode, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, parseBytes, physicalBytes, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, toString, totalBytes, totalPhysicalBytes, withDeallocator, zero
public static final int BRUTE_FORCE
public static final int KDTREE
public KNearest(Pointer p)
Pointer.Pointer(Pointer)
.public int getDefaultK()
setDefaultK
public void setDefaultK(int val)
public void setIsClassifier(@Cast(value="bool") boolean val)
public int getEmax()
setEmax
public void setEmax(int val)
public int getAlgorithmType()
setAlgorithmType
public void setAlgorithmType(int val)
public float findNearest(@ByVal Mat samples, int k, @ByVal Mat results, @ByVal(nullValue="cv::OutputArray(cv::noArray())") Mat neighborResponses, @ByVal(nullValue="cv::OutputArray(cv::noArray())") 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 UMat samples, int k, @ByVal UMat results, @ByVal(nullValue="cv::OutputArray(cv::noArray())") UMat neighborResponses, @ByVal(nullValue="cv::OutputArray(cv::noArray())") UMat dist)
public float findNearest(@ByVal GpuMat samples, int k, @ByVal GpuMat results, @ByVal(nullValue="cv::OutputArray(cv::noArray())") GpuMat neighborResponses, @ByVal(nullValue="cv::OutputArray(cv::noArray())") GpuMat dist)
@opencv_core.Ptr public static KNearest create()
The static method creates empty %KNearest classifier. It should be then trained using StatModel::train method.
@opencv_core.Ptr public static KNearest load(@opencv_core.Str BytePointer filepath)
filepath
- path to serialized KNearest@opencv_core.Ptr public static KNearest load(@opencv_core.Str String filepath)
Copyright © 2020. All rights reserved.