Purpose: updated the core chapter
This commit is contained in:
parent
77cdc746a5
commit
c6a6d71dae
@ -14,24 +14,23 @@ kmeans
|
||||
|
||||
: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
|
||||
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)
|
||||
* **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).
|
||||
|
||||
: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
|
||||
centers of ``clusterCount`` clusters and groups the input samples
|
||||
@ -46,10 +45,10 @@ The function returns the compactness measure, which is computed as
|
||||
|
||||
\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2
|
||||
|
||||
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.
|
||||
Basically, the user 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
|
||||
Basically, you can use only the core of the function, set the number of
|
||||
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.
|
||||
|
||||
.. index:: partition
|
||||
@ -62,9 +61,11 @@ partition
|
||||
|
||||
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 ``partition`` implements an
|
||||
:math:`O(N^2)` algorithm for
|
||||
|
@ -9,11 +9,11 @@ alignPtr
|
||||
------------
|
||||
.. c:function:: template<typename _Tp> _Tp* alignPtr(_Tp* ptr, int n=sizeof(_Tp))
|
||||
|
||||
Aligns pointer to the specified number of bytes
|
||||
Aligns a pointer to the specified number of bytes.
|
||||
|
||||
:param ptr: The aligned pointer
|
||||
:param ptr: Aligned pointer.
|
||||
|
||||
:param n: The alignment size; must be a power of two
|
||||
:param n: Alignment size that must be a power of two.
|
||||
|
||||
The function returns the aligned pointer of the same type as the input pointer:
|
||||
|
||||
@ -27,11 +27,11 @@ alignSize
|
||||
-------------
|
||||
.. c:function:: size_t alignSize(size_t sz, int n)
|
||||
|
||||
Aligns a buffer size to the specified number of bytes
|
||||
Aligns a buffer size to the specified number of bytes.
|
||||
|
||||
:param sz: The buffer size to align
|
||||
:param sz: Buffer size to align.
|
||||
|
||||
:param n: The alignment size; must be a power of two
|
||||
:param n: Alignment size that must be a power of two.
|
||||
|
||||
The function returns the minimum number that is greater or equal to ``sz`` and is divisble by ``n`` :
|
||||
|
||||
@ -45,11 +45,11 @@ allocate
|
||||
------------
|
||||
.. c:function:: template<typename _Tp> _Tp* allocate(size_t n)
|
||||
|
||||
Allocates an array of elements
|
||||
Allocates an array of elements.
|
||||
|
||||
:param n: The number of elements to allocate
|
||||
:param n: Number of elements to allocate.
|
||||
|
||||
The generic function ``allocate`` allocates buffer for the specified number of elements. For each element the default constructor is called.
|
||||
The generic function ``allocate`` allocates a buffer for the specified number of elements. For each element, the default constructor is called.
|
||||
|
||||
.. index:: deallocate
|
||||
|
||||
@ -57,11 +57,11 @@ deallocate
|
||||
--------------
|
||||
.. c:function:: template<typename _Tp> void deallocate(_Tp* ptr, size_t n)
|
||||
|
||||
Allocates an array of elements
|
||||
Allocates an array of elements.
|
||||
|
||||
:param ptr: Pointer to the deallocated buffer
|
||||
:param ptr: Pointer to the deallocated buffer.
|
||||
|
||||
:param n: The number of elements in the buffer
|
||||
:param n: Number of elements in the buffer.
|
||||
|
||||
The generic function ``deallocate`` deallocates the buffer allocated with
|
||||
:func:`allocate` . The number of elements must match the number passed to
|
||||
@ -81,9 +81,9 @@ CV_Assert
|
||||
#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.
|
||||
|
||||
.. index:: error
|
||||
@ -96,17 +96,19 @@ error
|
||||
|
||||
.. c:function:: \#define CV_Error_( code, args ) <...>
|
||||
|
||||
Signals an error and raises the exception
|
||||
Signals an error and raises an exception.
|
||||
|
||||
:param exc: The exception to throw
|
||||
:param exc: Exception to throw.
|
||||
|
||||
: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
|
||||
CV_Error_(CV_StsOutOfRange,
|
||||
@ -121,7 +123,7 @@ Exception
|
||||
---------
|
||||
.. c:type:: Exception
|
||||
|
||||
The exception class passed to error ::
|
||||
Exception class passed to error ::
|
||||
|
||||
class Exception
|
||||
{
|
||||
@ -145,7 +147,7 @@ The exception class passed to error ::
|
||||
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` .
|
||||
|
||||
.. index:: fastMalloc
|
||||
@ -154,11 +156,11 @@ fastMalloc
|
||||
--------------
|
||||
.. 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
|
||||
|
||||
@ -166,11 +168,11 @@ fastFree
|
||||
------------
|
||||
.. 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` .
|
||||
If NULL pointer is passed, the function does nothing.
|
||||
|
||||
@ -180,11 +182,11 @@ format
|
||||
----------
|
||||
.. c:function:: string format( const char* fmt, ... )
|
||||
|
||||
Returns a text string formatted using printf-like expression
|
||||
Returns a text string formatted using the ``printf`` -like expression.
|
||||
|
||||
:param fmt: The printf-compatible formatting specifiers
|
||||
:param fmt: ``printf`` -compatible formatting specifiers.
|
||||
|
||||
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.
|
||||
|
||||
.. index:: getNumThreads
|
||||
@ -193,12 +195,13 @@ 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.
|
||||
|
||||
See also:
|
||||
:func:`setNumThreads`,:func:`getThreadNum` .
|
||||
See Also:
|
||||
:func:`setNumThreads`,
|
||||
:func:`getThreadNum`
|
||||
|
||||
.. index:: getThreadNum
|
||||
|
||||
@ -206,12 +209,13 @@ 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:
|
||||
:func:`setNumThreads`,:func:`getNumThreads` .
|
||||
See Also:
|
||||
:func:`setNumThreads`,
|
||||
:func:`getNumThreads` .
|
||||
|
||||
.. index:: getTickCount
|
||||
|
||||
@ -219,9 +223,9 @@ 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
|
||||
: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()
|
||||
|
||||
Returns the number of ticks per second
|
||||
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();
|
||||
// do something ...
|
||||
@ -246,11 +250,12 @@ setNumThreads
|
||||
-----------------
|
||||
.. 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.
|
||||
|
||||
See also:
|
||||
:func:`getNumThreads`,:func:`getThreadNum`
|
||||
See Also:
|
||||
:func:`getNumThreads`,
|
||||
:func:`getThreadNum`
|
@ -11,7 +11,7 @@ FileStorage
|
||||
-----------
|
||||
.. c:type:: FileStorage
|
||||
|
||||
The XML/YAML file storage class ::
|
||||
XML/YAML file storage class ::
|
||||
|
||||
class FileStorage
|
||||
{
|
||||
@ -20,7 +20,7 @@ The XML/YAML file storage class ::
|
||||
enum { UNDEFINED=0, VALUE_EXPECTED=1, NAME_EXPECTED=2, INSIDE_MAP=4 };
|
||||
// the default constructor
|
||||
FileStorage();
|
||||
// the constructor that opens the file for reading
|
||||
// the constructor that opens a file for reading
|
||||
// (flags=FileStorage::READ) or writing (flags=FileStorage::WRITE)
|
||||
FileStorage(const string& filename, int flags);
|
||||
// wraps the already opened CvFileStorage*
|
||||
@ -39,7 +39,7 @@ The XML/YAML file storage class ::
|
||||
// returns the first top-level node
|
||||
FileNode getFirstTopLevelNode() const;
|
||||
// returns the root file node
|
||||
// (it's the parent of the first top-level node)
|
||||
// (it is the parent of the first top-level node)
|
||||
FileNode root(int streamidx=0) const;
|
||||
// returns the top-level node by name
|
||||
FileNode operator[](const string& nodename) const;
|
||||
@ -57,7 +57,7 @@ The XML/YAML file storage class ::
|
||||
void writeObj( const string& name, const void* obj );
|
||||
|
||||
// returns the default object name from the filename
|
||||
// (used by cvSave() with the default object name etc.)
|
||||
// (used by cvSave() with the default object name, etc.)
|
||||
static string getDefaultObjectName(const string& filename);
|
||||
|
||||
Ptr<CvFileStorage> fs;
|
||||
@ -74,7 +74,7 @@ FileNode
|
||||
--------
|
||||
.. c:type:: FileNode
|
||||
|
||||
The XML/YAML file node class ::
|
||||
XML/YAML file node class ::
|
||||
|
||||
class CV_EXPORTS FileNode
|
||||
{
|
||||
@ -124,7 +124,7 @@ FileNodeIterator
|
||||
----------------
|
||||
.. c:type:: FileNodeIterator
|
||||
|
||||
The XML/YAML file node iterator class ::
|
||||
XML/YAML file node iterator class ::
|
||||
|
||||
class CV_EXPORTS FileNodeIterator
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user