:param samples:Floating-point matrix of input samples, one row per sample.
:param samples:Floating-point matrix of input samples, one row per sample.
:param clusterCount:The number of clusters to split the set by.
:param clusterCount:Number of clusters to split the set by.
:param labels:The input/output integer array that stores the cluster indices for every sample.
:param labels:Input/output integer array that stores the cluster indices for every sample.
:param termcrit:Specifies the maximum number of iterations and/or accuracy (distance the centers can move by between subsequent iterations)
:param termcrit:Flag to specify the maximum number of iterations and/or accuracy (distance the centers can move by between subsequent iterations??).
:param attempts:How many times the algorithm is executed using different initial labelings. The algorithm returns the labels that yield the best compactness (see the last function parameter)
:param attempts:Flag to specify how many times the algorithm is executed using different initial labelings. The algorithm returns the labels that yield the best compactness (see the last function parameter).
:param flags:It can take the following values:
:param flags:Flag that can take the following values:
* **KMEANS_RANDOM_CENTERS** Random initial centers are selected in each attempt
* **KMEANS_RANDOM_CENTERS** Select random initial centers in each attempt.
* **KMEANS_PP_CENTERS** Use kmeans++ center initialization by Arthur and Vassilvitskii
* **KMEANS_PP_CENTERS** Use ``kmeans++`` center initialization by Arthur and Vassilvitskii.
* **KMEANS_USE_INITIAL_LABELS** During the first (and possibly the only) attempt, the
* **KMEANS_USE_INITIAL_LABELS** During the first (and possibly the only) attempt, use the user-supplied labels instead of computing them from the initial centers. For the second and further attempts, use the random or semi-random centers (use one of ``KMEANS_*_CENTERS`` flag to specify the exact method).
function uses the user-supplied labels instaed of computing them from the initial centers. For the second and further attempts, the function will use the random or semi-random centers (use one of ``KMEANS_*_CENTERS`` flag to specify the exact method)
:param centers:The output matrix of the cluster centers, one row per each cluster center
:param centers:Output matrix of the cluster centers, one row per each cluster center.
The function ``kmeans`` implements a k-means algorithm that finds the
The function ``kmeans`` implements a k-means algorithm that finds the
centers of ``clusterCount`` clusters and groups the input samples
centers of ``clusterCount`` clusters and groups the input samples
@ -46,10 +45,10 @@ The function returns the compactness measure, which is computed as
after every attempt; the best (minimum) value is chosen and the
after every attempt. The best (minimum) value is chosen and the
corresponding labels and the compactness value are returned by the function.
corresponding labels and the compactness value are returned by the function.
Basically, the user can use only the core of the function, set the number of
Basically, you can use only the core of the function, set the number of
attempts to 1, initialize labels each time using some custom algorithm and pass them with
attempts to 1, initialize labels each time using a custom algorithm, pass them with the
( ``flags`` = ``KMEANS_USE_INITIAL_LABELS`` ) flag, and then choose the best (most-compact) clustering.
( ``flags`` = ``KMEANS_USE_INITIAL_LABELS`` ) flag, and then choose the best (most-compact) clustering.
..index:: partition
..index:: partition
@ -62,9 +61,11 @@ partition
Splits an element set into equivalency classes.
Splits an element set into equivalency classes.
:param vec:The set of elements stored as a vector
:param vec:Set of elements stored as a vector.
:param labels:The output vector of labels; will contain as many elements as ``vec`` . Each label ``labels[i]`` is 0-based cluster index of ``vec[i]`` :param predicate: The equivalence predicate (i.e. pointer to a boolean function of two arguments or an instance of the class that has the method ``bool operator()(const _Tp& a, const _Tp& b)`` . The predicate returns true when the elements are certainly if the same class, and false if they may or may not be in the same class
:param labels:Output vector of labels. It contains as many elements as ``vec`` . Each label ``labels[i]`` is a 0-based cluster index of ``vec[i]`` .
:param predicate: Equivalence predicate (pointer to a boolean function of two arguments or an instance of the class that has the method ``bool operator()(const _Tp& a, const _Tp& b)`` ). The predicate returns ``true`` when the elements are certainly in the same class, and returns ``false`` if they may or may not be in the same class.
The generic function ``deallocate`` deallocates the buffer allocated with
The generic function ``deallocate`` deallocates the buffer allocated with
:func:`allocate` . The number of elements must match the number passed to
:func:`allocate` . The number of elements must match the number passed to
@ -81,9 +81,9 @@ CV_Assert
#define CV_DbgAssert(expr) ...
#define CV_DbgAssert(expr) ...
..
..
:param expr:The checked expression
:param expr:Expression to check.
The macros ``CV_Assert`` and ``CV_DbgAssert`` evaluate the specified expression and if it is 0, the macros raise an error (see
The macros ``CV_Assert`` and ``CV_DbgAssert`` evaluate the specified expression. If it is 0, the macros raise an error (see
:func:`error` ). The macro ``CV_Assert`` checks the condition in both Debug and Release configurations, while ``CV_DbgAssert`` is only retained in the Debug configuration.
:func:`error` ). The macro ``CV_Assert`` checks the condition in both Debug and Release configurations, while ``CV_DbgAssert`` is only retained in the Debug configuration.
:param code:The error code, normally, a negative value. The list of pre-defined error codes can be found in ``cxerror.h`` :param msg: Text of the error message
:param code:Error code. Normally, it is a negative value. The list of pre-defined error codes can be found in ``cxerror.h`` .
:param msg: Text of the error message.
:param args:printf-like formatted error message in parantheses
:param args:``printf`` -like formatted error message in parentheses.
The function and the helper macros ``CV_Error`` and ``CV_Error_`` call the error handler. Currently, the error handler prints the error code ( ``exc.code`` ), the context ( ``exc.file``,``exc.line`` and the error message ``exc.err`` to the standard error stream ``stderr`` . In Debug configuration it then provokes memory access violation, so that the execution stack and all the parameters can be analyzed in debugger. In Release configuration the exception ``exc`` is thrown.
The function and the helper macros ``CV_Error`` and ``CV_Error_`` call the error handler. Currently, the error handler prints the error code ( ``exc.code`` ), the context ( ``exc.file``,``exc.line``), and the error message ``exc.err`` to the standard error stream ``stderr`` . In the Debug configuration, it then provokes memory access violation, so that the execution stack and all the parameters can be analyzed by the debugger. In the Release configuration, the exception ``exc`` is thrown.
The macro ``CV_Error_`` can be used to construct the error message on-fly to include some dynamic information, for example: ::
The macro ``CV_Error_`` can be used to construct an error message on-fly to include some dynamic information, for example: ::
// note the extra parentheses around the formatted text message
// note the extra parentheses around the formatted text message
CV_Error_(CV_StsOutOfRange,
CV_Error_(CV_StsOutOfRange,
@ -121,7 +123,7 @@ Exception
---------
---------
..c:type:: Exception
..c:type:: Exception
The exception class passed to error ::
Exception class passed to error ::
class Exception
class Exception
{
{
@ -145,7 +147,7 @@ The exception class passed to error ::
int line;
int line;
};
};
The class ``Exception`` encapsulates all or almost all the necessary information about the error happened in the program. The exception is usually constructed and thrown implicitly, via ``CV_Error`` and ``CV_Error_`` macros, see
The class ``Exception`` encapsulates all or almost all the necessary information about the error happened in the program. The exception is usually constructed and thrown implicitly via ``CV_Error`` and ``CV_Error_`` macros. See
:func:`error` .
:func:`error` .
..index:: fastMalloc
..index:: fastMalloc
@ -154,11 +156,11 @@ fastMalloc
--------------
--------------
..c:function:: void* fastMalloc(size_t size)
..c:function:: void* fastMalloc(size_t size)
Allocates aligned memory buffer
Allocates an aligned memory buffer.
:param size:The allocated buffer size
:param size:Allocated buffer size.
The function allocates buffer of the specified size and returns it. When the buffer size is 16 bytes or more, the returned buffer is aligned on 16 bytes.
The function allocates the buffer of the specified size and returns it. When the buffer size is 16 bytes or more, the returned buffer is aligned on 16 bytes.
..index:: fastFree
..index:: fastFree
@ -166,11 +168,11 @@ fastFree
------------
------------
..c:function:: void fastFree(void* ptr)
..c:function:: void fastFree(void* ptr)
Deallocates memory buffer
Deallocates a memory buffer.
:param ptr:Pointer to the allocated buffer
:param ptr:Pointer to the allocated buffer.
The function deallocates the buffer, allocated with
The function deallocates the buffer allocated with
:func:`fastMalloc` .
:func:`fastMalloc` .
If NULL pointer is passed, the function does nothing.
If NULL pointer is passed, the function does nothing.
The function acts like ``sprintf``, but forms and returns STL string. It can be used for form the error message in
The function acts like ``sprintf`` but forms and returns an STL string. It can be used to form an error message in the
:func:`Exception` constructor.
:func:`Exception` constructor.
..index:: getNumThreads
..index:: getNumThreads
@ -193,12 +195,13 @@ getNumThreads
-----------------
-----------------
..c:function:: int getNumThreads()
..c:function:: int getNumThreads()
Returns the number of threads used by OpenCV
Returns the number of threads used by OpenCV.
The function returns the number of threads that is used by OpenCV.
The function returns the number of threads that is used by OpenCV.
See also:
See Also:
:func:`setNumThreads`,:func:`getThreadNum` .
:func:`setNumThreads`,
:func:`getThreadNum`
..index:: getThreadNum
..index:: getThreadNum
@ -206,12 +209,13 @@ getThreadNum
----------------
----------------
..c:function:: int getThreadNum()
..c:function:: int getThreadNum()
Returns index of the currently executed thread
Returns the index of the currently executed thread.
The function returns 0-based index of the currently executed thread. The function is only valid inside a parallel OpenMP region. When OpenCV is built without OpenMP support, the function always returns 0.
The function returns a 0-based index of the currently executed thread. The function is only valid inside a parallel OpenMP region. When OpenCV is built without OpenMP support, the function always returns 0.
See also:
See Also:
:func:`setNumThreads`,:func:`getNumThreads` .
:func:`setNumThreads`,
:func:`getNumThreads` .
..index:: getTickCount
..index:: getTickCount
@ -219,9 +223,9 @@ getTickCount
----------------
----------------
..c:function:: int64 getTickCount()
..c:function:: int64 getTickCount()
Returns the number of ticks
Returns the number of ticks.
The function returns the number of ticks since the certain event (e.g. when the machine was turned on).
The function returns the number of ticks after the certain event (for example, when the machine was turned on).
It can be used to initialize
It can be used to initialize
:func:`RNG` or to measure a function execution time by reading the tick count before and after the function call. See also the tick frequency.
:func:`RNG` or to measure a function execution time by reading the tick count before and after the function call. See also the tick frequency.
@ -231,10 +235,10 @@ getTickFrequency
--------------------
--------------------
..c:function:: double getTickFrequency()
..c:function:: double getTickFrequency()
Returns the number of ticks per second
Returns the number of ticks per second.
The function returns the number of ticks per second.
The function returns the number of ticks per second.
That is, the following code computes the execution time in seconds. ::
That is, the following code computes the execution time in seconds: ::
double t = (double)getTickCount();
double t = (double)getTickCount();
// do something ...
// do something ...
@ -246,11 +250,12 @@ setNumThreads
-----------------
-----------------
..c:function:: void setNumThreads(int nthreads)
..c:function:: void setNumThreads(int nthreads)
Sets the number of threads used by OpenCV
Sets the number of threads used by OpenCV.
:param nthreads:The number of threads used by OpenCV
:param nthreads:Number of threads used by OpenCV.
The function sets the number of threads used by OpenCV in parallel OpenMP regions. If ``nthreads=0`` , the function will use the default number of threads, which is usually equal to the number of the processing cores.
The function sets the number of threads used by OpenCV in parallel OpenMP regions. If ``nthreads=0`` , the function uses the default number of threads that is usually equal to the number of the processing cores.