merged all the latest changes from 2.4 to trunk

This commit is contained in:
Vadim Pisarevsky
2012-04-13 21:50:59 +00:00
parent 020f9a6047
commit 2fd1e2ea57
416 changed files with 12852 additions and 6070 deletions

View File

@@ -16,7 +16,13 @@ else()
set(cuda_link_libs "")
endif()
ocv_glob_module_sources(SOURCES ${lib_cuda} ${cuda_objs})
set(OPENCV_VERSION_FILE "${opencv_core_BINARY_DIR}/version_string.inc")
add_custom_command(OUTPUT "${OPENCV_VERSION_FILE}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENCV_BUILD_INFO_FILE}" "${OPENCV_VERSION_FILE}"
MAIN_DEPENDENCY "${OPENCV_BUILD_INFO_FILE}"
COMMENT "")
ocv_glob_module_sources(SOURCES ${lib_cuda} ${cuda_objs} "${OPENCV_VERSION_FILE}")
ocv_create_module(${cuda_link_libs})
ocv_add_precompiled_headers(${the_module})
@@ -24,6 +30,3 @@ ocv_add_precompiled_headers(${the_module})
ocv_add_accuracy_tests()
ocv_add_perf_tests()

View File

@@ -42,7 +42,7 @@ The main purpose of this class is to convert compilation-time type information t
cout << B.depth() << ", " << B.channels() << endl;
So, such traits are used to tell OpenCV which data type you are working with, even if such a type is not native to OpenCV. For example, the matrix ``B`` intialization above is compiled because OpenCV defines the proper specialized template class ``DataType<complex<_Tp> >`` . This mechanism is also useful (and used in OpenCV this way) for generic algorithms implementations.
So, such traits are used to tell OpenCV which data type you are working with, even if such a type is not native to OpenCV. For example, the matrix ``B`` initialization above is compiled because OpenCV defines the proper specialized template class ``DataType<complex<_Tp> >`` . This mechanism is also useful (and used in OpenCV this way) for generic algorithms implementations.
Point\_
@@ -100,7 +100,7 @@ Size\_
------
.. ocv:class:: Size_
Template class for specfying the size of an image or rectangle. The class includes two members called ``width`` and ``height``. The structure can be converted to and from the old OpenCV structures
Template class for specifying the size of an image or rectangle. The class includes two members called ``width`` and ``height``. The structure can be converted to and from the old OpenCV structures
``CvSize`` and ``CvSize2D32f`` . The same set of arithmetic and comparison operations as for ``Point_`` is available.
OpenCV defines the following ``Size_<>`` aliases: ::
@@ -372,7 +372,7 @@ This class provides the following options:
*
Heterogeneous collections of objects. The standard STL and most other C++ and OpenCV containers can store only objects of the same type and the same size. The classical solution to store objects of different types in the same container is to store pointers to the base class ``base_class_t*`` instead but then you loose the automatic memory management. Again, by using ``Ptr<base_class_t>()`` instead of the raw pointers, you can solve the problem.
The ``Ptr`` class treats the wrapped object as a black box. The reference counter is allocated and managed separately. The only thing the pointer class needs to know about the object is how to deallocate it. This knowledge is incapsulated in the ``Ptr::delete_obj()`` method that is called when the reference counter becomes 0. If the object is a C++ class instance, no additional coding is needed, because the default implementation of this method calls ``delete obj;`` .
The ``Ptr`` class treats the wrapped object as a black box. The reference counter is allocated and managed separately. The only thing the pointer class needs to know about the object is how to deallocate it. This knowledge is encapsulated in the ``Ptr::delete_obj()`` method that is called when the reference counter becomes 0. If the object is a C++ class instance, no additional coding is needed, because the default implementation of this method calls ``delete obj;`` .
However, if the object is deallocated in a different way, the specialized method should be created. For example, if you want to wrap ``FILE`` , the ``delete_obj`` may be implemented as follows: ::
template<> inline void Ptr<FILE>::delete_obj()
@@ -711,7 +711,7 @@ This is a list of implemented matrix operations that can be combined in arbitrar
*
``Mat_<destination_type>()`` constructors to cast the result to the proper type.
.. note:: Comma-separated initializers and probably some other operations may require additional explicit ``Mat()`` or ``Mat_<T>()`` constuctor calls to resolve a possible ambiguity.
.. note:: Comma-separated initializers and probably some other operations may require additional explicit ``Mat()`` or ``Mat_<T>()`` constructor calls to resolve a possible ambiguity.
Here are examples of matrix expressions:
@@ -786,6 +786,8 @@ Various Mat constructors
:param cols: Number of columns in a 2D array.
:param roi: Region of interest.
:param size: 2D array size: ``Size(cols, rows)`` . In the ``Size()`` constructor, the number of rows and the number of columns go in the reverse order.
:param sizes: Array of integers specifying an n-dimensional array shape.
@@ -890,7 +892,7 @@ The method makes a new header for the specified matrix row and returns it. This
// works, but looks a bit obscure.
A.row(i) = A.row(j) + 0;
// this is a bit longe, but the recommended method.
// this is a bit longer, but the recommended method.
A.row(j).copyTo(A.row(i));
Mat::col
@@ -996,7 +998,7 @@ When the operation mask is specified, and the ``Mat::create`` call shown above r
Mat::convertTo
------------------
Converts an array to another datatype with optional scaling.
Converts an array to another data type with optional scaling.
.. ocv:function:: void Mat::convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const
@@ -1008,7 +1010,7 @@ Converts an array to another datatype with optional scaling.
:param beta: Optional delta added to the scaled values.
The method converts source pixel values to the target datatype. ``saturate_cast<>`` is applied at the end to avoid possible overflows:
The method converts source pixel values to the target data type. ``saturate_cast<>`` is applied at the end to avoid possible overflows:
.. math::
@@ -1347,7 +1349,7 @@ Locates the matrix header within a parent matrix.
.. ocv:function:: void Mat::locateROI( Size& wholeSize, Point& ofs ) const
:param wholeSize: Output parameter that contains the size of the whole matrix containing ``*this`` is a part.
:param wholeSize: Output parameter that contains the size of the whole matrix containing ``*this`` as a part.
:param ofs: Output parameter that contains an offset of ``*this`` inside the whole matrix.
@@ -1380,7 +1382,7 @@ The method is complimentary to
In this example, the matrix size is increased by 4 elements in each direction. The matrix is shifted by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for the filtering with the 5x5 kernel.
It is your responsibility to make sure ``adjustROI`` does not cross the parent matrix boundary. If it does, the function signals an error.
``adjustROI`` forces the adjusted ROI to be inside of the parent matrix that is boundaries of the adjusted ROI are constrained by boundaries of the parent matrix. For example, if the submatrix ``A`` is located in the first row of a parent matrix and you called ``A.adjustROI(2, 2, 2, 2)`` then ``A`` will not be increased in the upward direction.
The function is used internally by the OpenCV filtering functions, like
:ocv:func:`filter2D` , morphological operations, and so on.
@@ -1600,7 +1602,7 @@ The method returns a matrix size: ``Size(cols, rows)`` . When the matrix is more
Mat::empty
--------------
Returns ``true`` if the array has no elemens.
Returns ``true`` if the array has no elements.
.. ocv:function:: bool Mat::empty() const

View File

@@ -11,9 +11,9 @@ Finds centers of clusters and groups input samples around the clusters.
.. ocv:pyfunction:: cv2.kmeans(data, K, criteria, attempts, flags[, bestLabels[, centers]]) -> retval, bestLabels, centers
.. ocv:cfunction:: int cvKMeans2(const CvArr* samples, int nclusters, CvArr* labels, CvTermCriteria criteria, int attempts=1, CvRNG* rng=0, int flags=0, CvArr* centers=0, double* compactness=0)
.. ocv:cfunction:: int cvKMeans2(const CvArr* samples, int clusterCount, CvArr* labels, CvTermCriteria criteria, int attempts=1, CvRNG* rng=0, int flags=0, CvArr* centers=0, double* compactness=0)
.. ocv:pyoldfunction:: cv.KMeans2(samples, nclusters, labels, criteria)-> None
.. ocv:pyoldfunction:: cv.KMeans2(samples, clusterCount, labels, criteria)-> None
:param samples: Floating-point matrix of input samples, one row per sample.
@@ -23,7 +23,9 @@ Finds centers of clusters and groups input samples around the clusters.
:param criteria: The algorithm termination criteria, that is, the maximum number of iterations and/or the desired accuracy. The accuracy is specified as ``criteria.epsilon``. As soon as each of the cluster centers moves by less than ``criteria.epsilon`` on some iteration, the algorithm stops.
:param attempts: Flag to specify the number of 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 the number of times the algorithm is executed using different initial labellings. The algorithm returns the labels that yield the best compactness (see the last function parameter).
:param rng: CvRNG state initialized by RNG().
:param flags: Flag that can take the following values:
@@ -35,6 +37,8 @@ Finds centers of clusters and groups input samples around the clusters.
:param centers: Output matrix of the cluster centers, one row per each cluster center.
:param compactness: The returned value that is described below.
The function ``kmeans`` implements a k-means algorithm that finds the
centers of ``clusterCount`` clusters and groups the input samples
around the clusters. As an output,

View File

@@ -190,7 +190,7 @@ Fills the area bounded by one or more polygons.
.. ocv:pyfunction:: cv2.fillPoly(img, pts, color[, lineType[, shift[, offset]]]) -> None
.. ocv:cfunction:: void cvFillPoly( CvArr* img, CvPoint** pts, int* npts, int contours, CvScalar color, int lineType=8, int shift=0 )
.. ocv:cfunction:: void cvFillPoly( CvArr* img, CvPoint** pts, int* npts, int ncontours, CvScalar color, int lineType=8, int shift=0 )
.. ocv:pyoldfunction:: cv.FillPoly(img, polys, color, lineType=8, shift=0)-> None
:param img: Image.
@@ -207,8 +207,10 @@ Fills the area bounded by one or more polygons.
:param shift: Number of fractional bits in the vertex coordinates.
:param offset: Optional offset of all points of the contours.
The function ``fillPoly`` fills an area bounded by several polygonal contours. The function can fill complex areas, for example,
areas with holes, contours with self-intersections (some of thier parts), and so forth.
areas with holes, contours with self-intersections (some of their parts), and so forth.
@@ -413,7 +415,7 @@ Draws a simple, thick, or filled up-right rectangle.
:param pt1: Vertex of the rectangle.
:param pt2: Vertex of the recangle opposite to ``pt1`` .
:param pt2: Vertex of the rectangle opposite to ``pt1`` .
:param r: Alternative specification of the drawn rectangle.

View File

@@ -34,7 +34,7 @@ A storage for various OpenCV dynamic data structures, such as ``CvSeq``, ``CvSet
Memory storage is a low-level structure used to store dynamically growing data structures such as sequences, contours, graphs, subdivisions, etc. It is organized as a list of memory blocks of equal size -
``bottom`` field is the beginning of the list of blocks and ``top`` is the currently used block, but not necessarily the last block of the list. All blocks between ``bottom`` and ``top``, not including the
latter, are considered fully occupied; all blocks between ``top`` and the last block, not including ``top``, are considered free and ``top`` itself is partly ocupied - ``free_space`` contains the number of free bytes left in the end of ``top``.
latter, are considered fully occupied; all blocks between ``top`` and the last block, not including ``top``, are considered free and ``top`` itself is partly occupied - ``free_space`` contains the number of free bytes left in the end of ``top``.
A new memory buffer that may be allocated explicitly by :ocv:cfunc:`MemStorageAlloc` function or implicitly by higher-level functions, such as :ocv:cfunc:`SeqPush`, :ocv:cfunc:`GraphAddEdge` etc.
@@ -126,16 +126,22 @@ There are helper functions to construct the slice and to compute its length:
.. ocv:cfunction:: CvSlice cvSlice( int start, int end )
:param start: Inclusive left boundary.
:param end: Exclusive right boundary.
::
#define CV_WHOLE_SEQ_END_INDEX 0x3fffffff
#define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX)
..
.. ocv:cfunction:: int cvSliceLength( CvSlice slice, const CvSeq* seq )
Calculates the sequence slice length
:param slice: The slice of sequence.
:param seq: Source sequence.
Calculates the sequence slice length.
Some of functions that operate on sequences take a ``CvSlice slice`` parameter that is often set to the whole sequence (CV_WHOLE_SEQ) by default. Either of the ``start_index`` and ``end_index`` may be negative or exceed the sequence length. If they are equal, the slice is considered empty (i.e., contains no elements). Because sequences are treated as circular structures, the slice may select a
few elements in the end of a sequence followed by a few elements at the beginning of the sequence. For example, ``cvSlice(-2, 3)`` in the case of a 10-element sequence will select a 5-element slice, containing the pre-last (8th), last (9th), the very first (0th), second (1th) and third (2nd)
@@ -338,7 +344,7 @@ Creates structure for depth-first graph traversal.
* **CV_GRAPH_BACK_EDGE** stop at back edges ( ``back edge`` is an edge connecting the last visited vertex with some of its ancestors in the search tree)
* **CV_GRAPH_FORWARD_EDGE** stop at forward edges ( ``forward edge`` is an edge conecting the last visited vertex with some of its descendants in the search tree. The forward edges are only possible during oriented graph traversal)
* **CV_GRAPH_FORWARD_EDGE** stop at forward edges ( ``forward edge`` is an edge connecting the last visited vertex with some of its descendants in the search tree. The forward edges are only possible during oriented graph traversal)
* **CV_GRAPH_CROSS_EDGE** stop at cross edges ( ``cross edge`` is an edge connecting different search trees or branches of the same tree. The ``cross edges`` are only possible during oriented graph traversal)
@@ -715,7 +721,7 @@ The function removes a vertex from the graph by using its pointer together with
GraphVtxDegree
--------------
Counts the number of edges indicent to the vertex.
Counts the number of edges incident to the vertex.
.. ocv:cfunction:: int cvGraphVtxDegree( const CvGraph* graph, int vtxIdx )
@@ -1222,7 +1228,7 @@ Searches for an element in a sequence.
:param elem_idx: Output parameter; index of the found element
:param userdata: The user parameter passed to the compasion function; helps to avoid global variables in some cases
:param userdata: The user parameter passed to the comparison function; helps to avoid global variables in some cases
::
@@ -1265,7 +1271,7 @@ Sorts sequence element using the specified comparison function.
:param func: The comparison function that returns a negative, zero, or positive value depending on the relationships among the elements (see the above declaration and the example below) - a similar function is used by ``qsort`` from C runline except that in the latter, ``userdata`` is not used
:param userdata: The user parameter passed to the compasion function; helps to avoid global variables in some cases
:param userdata: The user parameter passed to the comparison function; helps to avoid global variables in some cases
::
@@ -1552,5 +1558,5 @@ Gathers all node pointers to a single sequence.
:param storage: Container for the sequence
The function puts pointers of all nodes reacheable from ``first`` into a single sequence. The pointers are written sequentially in the depth-first order.
The function puts pointers of all nodes reachable from ``first`` into a single sequence. The pointers are written sequentially in the depth-first order.

View File

@@ -91,7 +91,7 @@ you can use::
Ptr<T> ptr = new T(...);
That is, ``Ptr<T> ptr`` incapsulates a pointer to a ``T`` instance and a reference counter associated with the pointer. See the
That is, ``Ptr<T> ptr`` encapsulates a pointer to a ``T`` instance and a reference counter associated with the pointer. See the
:ocv:class:`Ptr`
description for details.

View File

@@ -750,7 +750,7 @@ or:
DotProduct
----------
Calculates the dot product of two arrays in Euclidian metrics.
Calculates the dot product of two arrays in Euclidean metrics.
.. ocv:cfunction:: double cvDotProduct(const CvArr* src1, const CvArr* src2)
.. ocv:pyoldfunction:: cv.DotProduct(src1, src2)-> double
@@ -937,7 +937,7 @@ The function provides an easy way to handle both types of arrays - ``IplImage``
.. seealso:: :ocv:cfunc:`GetImage`, :ocv:func:`cvarrToMat`.
.. note:: If the input array is ``IplImage`` with planar data layout and COI set, the function returns the pointer to the selected plane and ``COI == 0``. This feature allows user to process ``IplImage`` strctures with planar data layout, even though OpenCV does not support such images.
.. note:: If the input array is ``IplImage`` with planar data layout and COI set, the function returns the pointer to the selected plane and ``COI == 0``. This feature allows user to process ``IplImage`` structures with planar data layout, even though OpenCV does not support such images.
GetNextSparseNode
-----------------

View File

@@ -144,7 +144,7 @@ Type information. ::
..
The structure contains information about one of the standard or user-defined types. Instances of the type may or may not contain a pointer to the corresponding :ocv:struct:`CvTypeInfo` structure. In any case, there is a way to find the type info structure for a given object using the :ocv:cfunc:`TypeOf` function. Aternatively, type info can be found by type name using :ocv:cfunc:`FindType`, which is used when an object is read from file storage. The user can register a new type with :ocv:cfunc:`RegisterType`
The structure contains information about one of the standard or user-defined types. Instances of the type may or may not contain a pointer to the corresponding :ocv:struct:`CvTypeInfo` structure. In any case, there is a way to find the type info structure for a given object using the :ocv:cfunc:`TypeOf` function. Alternatively, type info can be found by type name using :ocv:cfunc:`FindType`, which is used when an object is read from file storage. The user can register a new type with :ocv:cfunc:`RegisterType`
that adds the type information structure into the beginning of the type list. Thus, it is possible to create specialized types from generic standard types and override the basic methods.
Clone
@@ -215,7 +215,7 @@ Finds a node in a map or file storage.
:param name: The file node name
The function finds a file node by ``name``. The node is searched either in ``map`` or, if the pointer is NULL, among the top-level file storage nodes. Using this function for maps and :ocv:cfunc:`GetSeqElem`
(or sequence reader) for sequences, it is possible to nagivate through the file storage. To speed up multiple queries for a certain key (e.g., in the case of an array of structures) one may use a combination of :ocv:cfunc:`GetHashedKey` and :ocv:cfunc:`GetFileNode`.
(or sequence reader) for sequences, it is possible to navigate through the file storage. To speed up multiple queries for a certain key (e.g., in the case of an array of structures) one may use a combination of :ocv:cfunc:`GetHashedKey` and :ocv:cfunc:`GetFileNode`.
GetFileNodeName
---------------
@@ -356,7 +356,7 @@ Opens file storage for reading or writing data.
* **CV_STORAGE_WRITE** the storage is open for writing
The function opens file storage for reading or writing data. In the latter case, a new file is created or an existing file is rewritten. The type of the read or written file is determined by the filename extension: ``.xml`` for ``XML`` and ``.yml`` or ``.yaml`` for ``YAML``. The function returns a pointer to the :ocv:struct:`CvFileStorage` structure.
The function opens file storage for reading or writing data. In the latter case, a new file is created or an existing file is rewritten. The type of the read or written file is determined by the filename extension: ``.xml`` for ``XML`` and ``.yml`` or ``.yaml`` for ``YAML``. The function returns a pointer to the :ocv:struct:`CvFileStorage` structure. If the file cannot be opened then the function returns ``NULL``.
Read
----
@@ -629,7 +629,7 @@ The function finishes the currently written stream and starts the next stream. I
</opencv_storage>
...
The a YAML file will look like this: ::
The YAML file will look like this: ::
%YAML:1.0
# stream #1 data
@@ -722,7 +722,7 @@ Writes an object to file storage.
:param ptr: Pointer to the object
:param attributes: The attributes of the object. They are specific for each particular type (see the dicsussion below).
:param attributes: The attributes of the object. They are specific for each particular type (see the discussion below).
The function writes an object to file storage. First, the appropriate type info is found using :ocv:cfunc:`TypeOf`. Then, the ``write`` method associated with the type info is called.
@@ -796,7 +796,7 @@ Writes a file node to another file storage.
:param node: The written node
:param embed: If the written node is a collection and this parameter is not zero, no extra level of hiararchy is created. Instead, all the elements of ``node`` are written into the currently written structure. Of course, map elements can only be embedded into another map, and sequence elements can only be embedded into another sequence.
:param embed: If the written node is a collection and this parameter is not zero, no extra level of hierarchy is created. Instead, all the elements of ``node`` are written into the currently written structure. Of course, map elements can only be embedded into another map, and sequence elements can only be embedded into another sequence.
The function writes a copy of a file node to file storage. Possible applications of the function are merging several file storages into one and conversion between XML and YAML formats.

View File

@@ -208,7 +208,7 @@ Calculates the per-element bit-wise conjunction of two arrays or an array and a
:param src2: Second source array or a scalar.
:param dst: Destination arrayb that has the same size and type as the input array(s).
:param dst: Destination array that has the same size and type as the input array(s).
:param mask: Optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed.
@@ -1124,6 +1124,37 @@ To extract a channel from a new-style matrix, use
.. seealso:: :ocv:func:`mixChannels` , :ocv:func:`split` , :ocv:func:`merge` , :ocv:func:`cvarrToMat` , :ocv:cfunc:`cvSetImageCOI` , :ocv:cfunc:`cvGetImageCOI`
insertImageCOI
---------------
Copies the selected image channel from a new-style C++ matrix to the old-style C array.
.. ocv:function:: void insertImageCOI(InputArray src, CvArr* dst, int coi=-1)
:param src: Source array with a single channel and the same size and depth as ``dst``.
:param dst: Destination array, it should be a pointer to ``CvMat`` or ``IplImage``.
:param coi: If the parameter is ``>=0`` , it specifies the channel to insert. If it is ``<0`` and ``dst`` is a pointer to ``IplImage`` with a valid COI set, the selected COI is extracted.
The function ``insertImageCOI`` is used to extract an image COI from a new-style C++ matrix and put the result to the old-style array.
The sample below illustrates how to use the function:
::
Mat temp(240, 320, CV_8UC1, Scalar(255));
IplImage* img = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 3);
insertImageCOI(temp, img, 1); //insert to the first channel
cvNamedWindow("window",1);
cvShowImage("window", img); //you should see green image, because channel number 1 is green (BGR)
cvWaitKey(0);
cvDestroyAllWindows();
cvReleaseImage(&img);
To insert a channel to a new-style matrix, use
:ocv:func:`merge` .
.. seealso:: :ocv:func:`mixChannels` , :ocv:func:`split` , :ocv:func:`merge` , :ocv:func:`cvarrToMat` , :ocv:cfunc:`cvSetImageCOI` , :ocv:cfunc:`cvGetImageCOI`
flip
--------
@@ -1182,7 +1213,7 @@ Performs generalized matrix multiplication.
.. ocv:pyfunction:: cv2.gemm(src1, src2, alpha, src3, gamma[, dst[, flags]]) -> dst
.. ocv:cfunction:: void cvGEMM( const CvArr* src1, const CvArr* src2, double alpha, const CvArr* src3, double beta, CvArr* dst, int tABC=0)
.. ocv:pyoldfunction:: cv.GEMM(src1, src2, alphs, src3, beta, dst, tABC=0)-> None
.. ocv:pyoldfunction:: cv.GEMM(src1, src2, alpha, src3, beta, dst, tABC=0)-> None
:param src1: First multiplied input matrix that should have ``CV_32FC1`` , ``CV_64FC1`` , ``CV_32FC2`` , or ``CV_64FC2`` type.
@@ -1373,7 +1404,7 @@ The function checks the range as follows:
That is, ``dst`` (I) is set to 255 (all ``1`` -bits) if ``src`` (I) is within the specified 1D, 2D, 3D, ... box and 0 otherwise.
When the lower and/or upper bounary parameters are scalars, the indexes ``(I)`` at ``lowerb`` and ``upperb`` in the above formulas should be omitted.
When the lower and/or upper boundary parameters are scalars, the indexes ``(I)`` at ``lowerb`` and ``upperb`` in the above formulas should be omitted.
invert
@@ -1398,7 +1429,7 @@ Finds the inverse or pseudo-inverse of a matrix.
* **DECOMP_SVD** Singular value decomposition (SVD) method.
* **DECOMP_CHOLESKY** Cholesky decomposion. The matrix must be symmetrical and positively defined.
* **DECOMP_CHOLESKY** Cholesky decomposition. The matrix must be symmetrical and positively defined.
The function ``invert`` inverts the matrix ``src`` and stores the result in ``dst`` .
When the matrix ``src`` is singular or non-square, the function computes the pseudo-inverse matrix (the ``dst`` matrix) so that ``norm(src*dst - I)`` is minimal, where I is an identity matrix.
@@ -2097,7 +2128,7 @@ Normalizes the norm or value range of an array.
:param alpha: Norm value to normalize to or the lower range boundary in case of the range normalization.
:param beta: Upper range boundary in case ofthe range normalization. It is not used for the norm normalization.
:param beta: Upper range boundary in case of the range normalization. It is not used for the norm normalization.
:param normType: Normalization type. See the details below.
@@ -2423,6 +2454,8 @@ So, for a non-integer power exponent, the absolute values of input array element
For some values of ``p`` , such as integer values, 0.5 and -0.5, specialized faster algorithms are used.
Special values (NaN, Inf) are not handled.
.. seealso::
:ocv:func:`sqrt`,
@@ -3021,7 +3054,7 @@ If you need to extract a single channel or do some other sophisticated channel p
sqrt
----
Calculates a quare root of array elements.
Calculates a square root of array elements.
.. ocv:function:: void sqrt(InputArray src, OutputArray dst)
@@ -3203,7 +3236,7 @@ Performs SVD of a matrix
:param vt: Transposed matrix of right singular values
:param flags: Opertion flags - see :ocv:func:`SVD::SVD`.
:param flags: Operation flags - see :ocv:func:`SVD::SVD`.
The methods/functions perform SVD of matrix. Unlike ``SVD::SVD`` constructor and ``SVD::operator()``, they store the results to the user-provided matrices. ::

View File

@@ -31,7 +31,7 @@ Aligns a buffer size to the specified number of bytes.
: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`` :
The function returns the minimum number that is greater or equal to ``sz`` and is divisible by ``n`` :
.. math::

View File

@@ -148,17 +148,545 @@ FileStorage
-----------
.. ocv:class:: FileStorage
XML/YAML file storage class that incapsulates all the information necessary for writing or reading data to/from file.
XML/YAML file storage class that encapsulates all the information necessary for writing or reading data to/from a file.
FileStorage::FileStorage
------------------------
The constructors.
.. ocv:function:: FileStorage::FileStorage()
.. ocv:function:: FileStorage::FileStorage(const string& filename, int flags, const string& encoding=string())
:param filename: Name of the file to open. Extension of the file (``.xml`` or ``.yml``/``.yaml``) determines its format (XML or YAML respectively). Also you can append ``.gz`` to work with compressed files, for example ``myHugeMatrix.xml.gz``.
:param flags: Mode of operation. Possible values are:
* **FileStorage::READ** Open the file for reading.
* **FileStorage::WRITE** Open the file for writing.
* **FileStorage::APPEND** Open the file for appending.
:param encoding: Encoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.
The full constructor opens the file. Alternatively you can use the default constructor and then call :ocv:func:`FileStorage::open`.
FileStorage::open
-----------------
Opens a file.
.. ocv:function:: bool FileStorage::open(const string& filename, int flags, const string& encoding=string())
See description of parameters in :ocv:func:`FileStorage::FileStorage`. The method calls :ocv:func:`FileStorage::release` before opening the file.
FileStorage::isOpened
---------------------
Checks whether the file is opened.
.. ocv:function:: bool FileStorage::isOpened() const
:returns: ``true`` if the object is associated with the current file and ``false`` otherwise.
It is a good practice to call this method after you tried to open a file.
FileStorage::release
--------------------
Closes the file and releases all the memory buffers.
.. ocv:function:: void FileStorage::release()
Call this method after all I/O operations with the storage are finished.
FileStorage::getFirstTopLevelNode
---------------------------------
Returns the first element of the top-level mapping.
.. ocv:function:: FileNode FileStorage::getFirstTopLevelNode() const
:returns: The first element of the top-level mapping.
FileStorage::root
-----------------
Returns the top-level mapping
.. ocv:function:: FileNode FileStorage::root(int streamidx=0) const
:param streamidx: Zero-based index of the stream. In most cases there is only one stream in the file. However, YAML supports multiple streams and so there can be several.
:returns: The top-level mapping.
FileStorage::operator[]
-----------------------
Returns the specified element of the top-level mapping.
.. ocv:function:: FileNode FileStorage::operator[](const string& nodename) const
.. ocv:function:: FileNode FileStorage::operator[](const char* nodename) const
:param nodename: Name of the file node.
:returns: Node with the given name.
FileStorage::operator*
----------------------
Returns the obsolete C FileStorage structure.
.. ocv:function:: CvFileStorage* FileStorage::operator *()
.. ocv:function:: const CvFileStorage* FileStorage::operator *() const
:returns: Pointer to the underlying C FileStorage structure
FileStorage::writeRaw
---------------------
Writes multiple numbers.
.. ocv:function:: void FileStorage::writeRaw( const string& fmt, const uchar* vec, size_t len )
:param fmt: Specification of each array element that has the following format ``([count]{'u'|'c'|'w'|'s'|'i'|'f'|'d'})...`` where the characters correspond to fundamental C++ types:
* **u** 8-bit unsigned number
* **c** 8-bit signed number
* **w** 16-bit unsigned number
* **s** 16-bit signed number
* **i** 32-bit signed number
* **f** single precision floating-point number
* **d** double precision floating-point number
* **r** pointer, 32 lower bits of which are written as a signed integer. The type can be used to store structures with links between the elements.
``count`` is the optional counter of values of a given type. For example, ``2if`` means that each array element is a structure of 2 integers, followed by a single-precision floating-point number. The equivalent notations of the above specification are ' ``iif`` ', ' ``2i1f`` ' and so forth. Other examples: ``u`` means that the array consists of bytes, and ``2d`` means the array consists of pairs of doubles.
:param vec: Pointer to the written array.
:param len: Number of the ``uchar`` elements to write.
Writes one or more numbers of the specified format to the currently written structure. Usually it is more convenient to use :ocv:func:`operator <<` instead of this method.
FileStorage::writeObj
---------------------
Writes the registered C structure (CvMat, CvMatND, CvSeq).
.. ocv:function:: void FileStorage::writeObj( const string& name, const void* obj )
:param name: Name of the written object.
:param obj: Pointer to the object.
See :ocv:cfunc:`Write` for details.
FileStorage::getDefaultObjectName
---------------------------------
Returns the normalized object name for the specified name of a file.
.. ocv:function:: static string FileStorage::getDefaultObjectName(const string& filename)
:param filename: Name of a file
:returns: The normalized object name.
operator <<
-----------
Writes data to a file storage.
.. ocv:function:: template<typename _Tp> FileStorage& operator << (FileStorage& fs, const _Tp& value)
.. ocv:function:: template<typename _Tp> FileStorage& operator << ( FileStorage& fs, const vector<_Tp>& vec )
:param fs: Opened file storage to write data.
:param value: Value to be written to the file storage.
:param vec: Vector of values to be written to the file storage.
It is the main function to write data to a file storage. See an example of its usage at the beginning of the section.
operator >>
-----------
Reads data from a file storage.
.. ocv:function:: template<typename _Tp> void operator >> (const FileNode& n, _Tp& value)
.. ocv:function:: template<typename _Tp> void operator >> (const FileNode& n, vector<_Tp>& vec)
.. ocv:function:: template<typename _Tp> FileNodeIterator& operator >> (FileNodeIterator& it, _Tp& value)
.. ocv:function:: template<typename _Tp> FileNodeIterator& operator >> (FileNodeIterator& it, vector<_Tp>& vec)
:param n: Node from which data will be read.
:param it: Iterator from which data will be read.
:param value: Value to be read from the file storage.
:param vec: Vector of values to be read from the file storage.
It is the main function to read data from a file storage. See an example of its usage at the beginning of the section.
FileNode
--------
.. ocv:class:: FileNode
The class ``FileNode`` represents each element of the file storage, be it a matrix, a matrix element or a top-level node, containing all the file content. That is, a file node may contain either a singe value (integer, floating-point value or a text string), or it can be a sequence of other file nodes, or it can be a mapping. Type of the file node can be determined using :ocv:func:`FileNode::type` method.
File Storage Node class. The node is used to store each and every element of the file storage opened for reading. When XML/YAML file is read, it is first parsed and stored in the memory as a hierarchical collection of nodes. Each node can be a “leaf” that is contain a single number or a string, or be a collection of other nodes. There can be named collections (mappings) where each element has a name and it is accessed by a name, and ordered collections (sequences) where elements do not have names but rather accessed by index. Type of the file node can be determined using :ocv:func:`FileNode::type` method.
Note that file nodes are only used for navigating file storages opened for reading. When a file storage is opened for writing, no data is stored in memory after it is written.
FileNode::FileNode
------------------
The constructors.
.. ocv:function:: FileNode::FileNode()
.. ocv:function:: FileNode::FileNode(const CvFileStorage* fs, const CvFileNode* node)
.. ocv:function:: FileNode::FileNode(const FileNode& node)
:param fs: Pointer to the obsolete file storage structure.
:param node: File node to be used as initialization for the created file node.
These constructors are used to create a default file node, construct it from obsolete structures or from the another file node.
FileNode::operator[]
--------------------
Returns element of a mapping node or a sequence node.
.. ocv:function:: FileNode FileNode::operator[](const string& nodename) const
.. ocv:function:: FileNode FileNode::operator[](const char* nodename) const
.. ocv:function:: FileNode FileNode::operator[](int i) const
:param nodename: Name of an element in the mapping node.
:param i: Index of an element in the sequence node.
:returns: Returns the element with the given identifier.
FileNode::type
--------------
Returns type of the node.
.. ocv:function:: int FileNode::type() const
:returns: Type of the node. Possible values are:
* **FileNode::NONE** Empty node.
* **FileNode::INT** Integer.
* **FileNode::REAL** Floating-point number.
* **FileNode::FLOAT** Synonym or ``REAL``.
* **FileNode::STR** Text string in UTF-8 encoding.
* **FileNode::STRING** Synonym for ``STR``.
* **FileNode::REF** Integer of type ``size_t``. Typically used for storing complex dynamic structures where some elements reference the others.
* **FileNode::SEQ** Sequence.
* **FileNode::MAP** Mapping.
* **FileNode::FLOW** Compact representation of a sequence or mapping. Used only by the YAML writer.
* **FileNode::USER** Registered object (e.g. a matrix).
* **FileNode::EMPTY** Empty structure (sequence or mapping).
* **FileNode::NAMED** The node has a name (i.e. it is an element of a mapping).
FileNode::empty
---------------
Checks whether the node is empty.
.. ocv:function:: bool FileNode::empty() const
:returns: ``true`` if the node is empty.
FileNode::isNone
----------------
Checks whether the node is a "none" object
.. ocv:function:: bool FileNode::isNone() const
:returns: ``true`` if the node is a "none" object.
FileNode::isSeq
---------------
Checks whether the node is a sequence.
.. ocv:function:: bool FileNode::isSeq() const
:returns: ``true`` if the node is a sequence.
FileNode::isMap
---------------
Checks whether the node is a mapping.
.. ocv:function:: bool FileNode::isMap() const
:returns: ``true`` if the node is a mapping.
FileNode::isInt
---------------
Checks whether the node is an integer.
.. ocv:function:: bool FileNode::isInt() const
:returns: ``true`` if the node is an integer.
FileNode::isReal
----------------
Checks whether the node is a floating-point number.
.. ocv:function:: bool FileNode::isReal() const
:returns: ``true`` if the node is a floating-point number.
FileNode::isString
------------------
Checks whether the node is a text string.
.. ocv:function:: bool FileNode::isString() const
:returns: ``true`` if the node is a text string.
FileNode::isNamed
-----------------
Checks whether the node has a name.
.. ocv:function:: bool FileNode::isNamed() const
:returns: ``true`` if the node has a name.
FileNode::name
--------------
Returns the node name.
.. ocv:function:: string FileNode::name() const
:returns: The node name or an empty string if the node is nameless.
FileNode::size
--------------
Returns the number of elements in the node.
.. ocv:function:: size_t FileNode::size() const
:returns: The number of elements in the node, if it is a sequence or mapping, or 1 otherwise.
FileNode::operator int
----------------------
Returns the node content as an integer.
.. ocv:function:: FileNode::operator int() const
:returns: The node content as an integer. If the node stores a floating-point number, it is rounded.
FileNode::operator float
------------------------
Returns the node content as float.
.. ocv:function:: FileNode::operator float() const
:returns: The node content as float.
FileNode::operator double
-------------------------
Returns the node content as double.
.. ocv:function:: FileNode::operator double() const
:returns: The node content as double.
FileNode::operator string
-------------------------
Returns the node content as text string.
.. ocv:function:: FileNode::operator string() const
:returns: The node content as a text string.
FileNode::operator*
-------------------
Returns pointer to the underlying obsolete file node structure.
.. ocv:function:: CvFileNode* FileNode::operator *()
:returns: Pointer to the underlying obsolete file node structure.
FileNode::begin
---------------
Returns the iterator pointing to the first node element.
.. ocv:function:: FileNodeIterator FileNode::begin() const
:returns: Iterator pointing to the first node element.
FileNode::end
-------------
Returns the iterator pointing to the element following the last node element.
.. ocv:function:: FileNodeIterator FileNode::end() const
:returns: Iterator pointing to the element following the last node element.
FileNode::readRaw
-----------------
Reads node elements to the buffer with the specified format.
.. ocv:function:: void FileNode::readRaw( const string& fmt, uchar* vec, size_t len ) const
:param fmt: Specification of each array element. It has the same format as in :ocv:func:`FileStorage::writeRaw`.
:param vec: Pointer to the destination array.
:param len: Number of elements to read. If it is greater than number of remaining elements then all of them will be read.
Usually it is more convenient to use :ocv:func:`operator >>` instead of this method.
FileNode::readObj
-----------------
Reads the registered object.
.. ocv:function:: void* FileNode::readObj() const
:returns: Pointer to the read object.
See :ocv:cfunc:`Read` for details.
FileNodeIterator
----------------
.. ocv:class:: FileNodeIterator
The class ``FileNodeIterator`` is used to iterate through sequences and mappings. A standard STL notation, with ``node.begin()``, ``node.end()`` denoting the beginning and the end of a sequence, stored in ``node``. See the data reading sample in the beginning of the section.
FileNodeIterator::FileNodeIterator
----------------------------------
The constructors.
.. ocv:function:: FileNodeIterator::FileNodeIterator()
.. ocv:function:: FileNodeIterator::FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0)
.. ocv:function:: FileNodeIterator::FileNodeIterator(const FileNodeIterator& it)
:param fs: File storage for the iterator.
:param node: File node for the iterator.
:param ofs: Index of the element in the node. The created iterator will point to this element.
:param it: Iterator to be used as initialization for the created iterator.
These constructors are used to create a default iterator, set it to specific element in a file node or construct it from another iterator.
FileNodeIterator::operator*
---------------------------
Returns the currently observed element.
.. ocv:function:: FileNode FileNodeIterator::operator *() const
:returns: Currently observed element.
FileNodeIterator::operator->
----------------------------
Accesses methods of the currently observed element.
.. ocv:function:: FileNode FileNodeIterator::operator ->() const
FileNodeIterator::operator ++
-----------------------------
Moves iterator to the next node.
.. ocv:function:: FileNodeIterator& FileNodeIterator::operator ++ ()
.. ocv:function:: FileNodeIterator FileNodeIterator::operator ++ (int)
FileNodeIterator::operator --
-----------------------------
Moves iterator to the previous node.
.. ocv:function:: FileNodeIterator& FileNodeIterator::operator -- ()
.. ocv:function:: FileNodeIterator FileNodeIterator::operator -- (int)
FileNodeIterator::operator +=
-----------------------------
Moves iterator forward by the specified offset.
.. ocv:function:: FileNodeIterator& FileNodeIterator::operator += (int ofs)
:param ofs: Offset (possibly negative) to move the iterator.
FileNodeIterator::operator -=
-----------------------------
Moves iterator backward by the specified offset (possibly negative).
.. ocv:function:: FileNodeIterator& FileNodeIterator::operator -= (int ofs)
:param ofs: Offset (possibly negative) to move the iterator.
FileNodeIterator::readRaw
-------------------------
Reads node elements to the buffer with the specified format.
.. ocv:function:: FileNodeIterator& FileNodeIterator::readRaw( const string& fmt, uchar* vec, size_t maxCount=(size_t)INT_MAX )
:param fmt: Specification of each array element. It has the same format as in :ocv:func:`FileStorage::writeRaw`.
:param vec: Pointer to the destination array.
:param maxCount: Number of elements to read. If it is greater than number of remaining elements then all of them will be read.
Usually it is more convenient to use :ocv:func:`operator >>` instead of this method.

View File

@@ -218,6 +218,8 @@ CV_EXPORTS void setNumThreads(int nthreads);
CV_EXPORTS int getNumThreads();
CV_EXPORTS int getThreadNum();
CV_EXPORTS_W const std::string& getBuildInformation();
//! Returns the number of ticks.
/*!
@@ -1944,6 +1946,9 @@ public:
MSize size;
MStep step;
protected:
void initEmpty();
};
@@ -2727,7 +2732,6 @@ public:
static MatExpr eye(Size size);
//! some more overriden methods
Mat_ reshape(int _rows) const;
Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright );
Mat_ operator()( const Range& rowRange, const Range& colRange ) const;
Mat_ operator()( const Rect& roi ) const;
@@ -4273,6 +4277,7 @@ public:
void set(const string& name, bool value);
void set(const string& name, const string& value);
void set(const string& name, const Mat& value);
void set(const string& name, const vector<Mat>& value);
void set(const string& name, const Ptr<Algorithm>& value);
void set(const char* name, int value);
@@ -4280,6 +4285,7 @@ public:
void set(const char* name, bool value);
void set(const char* name, const string& value);
void set(const char* name, const Mat& value);
void set(const char* name, const vector<Mat>& value);
void set(const char* name, const Ptr<Algorithm>& value);
string paramHelp(const string& name) const;
@@ -4347,6 +4353,11 @@ public:
Mat (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const Mat&)=0,
const string& help=string());
void addParam(Algorithm& algo, const char* name,
vector<Mat>& value, bool readOnly=false,
vector<Mat> (Algorithm::*getter)()=0,
void (Algorithm::*setter)(const vector<Mat>&)=0,
const string& help=string());
void addParam(Algorithm& algo, const char* name,
Ptr<Algorithm>& value, bool readOnly=false,
Ptr<Algorithm> (Algorithm::*getter)()=0,
@@ -4359,7 +4370,7 @@ protected:
struct CV_EXPORTS Param
{
enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, ALGORITHM=5 };
enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6 };
Param();
Param(int _type, bool _readonly, int _offset,
@@ -4414,6 +4425,14 @@ template<> struct ParamType<Mat>
enum { type = Param::MAT };
};
template<> struct ParamType<vector<Mat> >
{
typedef const vector<Mat>& const_param_type;
typedef vector<Mat> member_type;
enum { type = Param::MAT_VECTOR };
};
template<> struct ParamType<Algorithm>
{
typedef const Ptr<Algorithm>& const_param_type;

View File

@@ -59,7 +59,7 @@ namespace cv
// It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile
template <bool expr> struct StaticAssert;
template <> struct StaticAssert<true> {static __CV_GPU_HOST_DEVICE__ void check(){}};
template <> struct StaticAssert<true> {static __CV_GPU_HOST_DEVICE__ void check(){}};
template<typename T> struct DevPtr
{

View File

@@ -55,53 +55,55 @@ namespace cv
//////////////////////////////// Mat ////////////////////////////////
inline Mat::Mat()
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
inline void Mat::initEmpty()
{
flags = MAGIC_VAL;
dims = rows = cols = 0;
data = datastart = dataend = datalimit = 0;
refcount = 0;
allocator = 0;
}
inline Mat::Mat() : size(&rows)
{
initEmpty();
}
inline Mat::Mat(int _rows, int _cols, int _type)
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
inline Mat::Mat(int _rows, int _cols, int _type) : size(&rows)
{
initEmpty();
create(_rows, _cols, _type);
}
inline Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s)
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
inline Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) : size(&rows)
{
initEmpty();
create(_rows, _cols, _type);
*this = _s;
}
inline Mat::Mat(Size _sz, int _type)
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
inline Mat::Mat(Size _sz, int _type) : size(&rows)
{
initEmpty();
create( _sz.height, _sz.width, _type );
}
inline Mat::Mat(Size _sz, int _type, const Scalar& _s)
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
inline Mat::Mat(Size _sz, int _type, const Scalar& _s) : size(&rows)
{
initEmpty();
create(_sz.height, _sz.width, _type);
*this = _s;
}
inline Mat::Mat(int _dims, const int* _sz, int _type)
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
inline Mat::Mat(int _dims, const int* _sz, int _type) : size(&rows)
{
initEmpty();
create(_dims, _sz, _type);
}
inline Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s)
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
inline Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s) : size(&rows)
{
initEmpty();
create(_dims, _sz, _type);
*this = _s;
}
@@ -169,27 +171,6 @@ inline Mat::Mat(Size _sz, int _type, void* _data, size_t _step)
}
inline Mat::Mat(const CvMat* m, bool copyData)
: flags(MAGIC_VAL + (m->type & (CV_MAT_TYPE_MASK|CV_MAT_CONT_FLAG))),
dims(2), rows(m->rows), cols(m->cols), data(m->data.ptr), refcount(0),
datastart(m->data.ptr), allocator(0), size(&rows)
{
if( !copyData )
{
size_t esz = CV_ELEM_SIZE(m->type), minstep = cols*esz, _step = m->step;
if( _step == 0 )
_step = minstep;
datalimit = datastart + _step*rows;
dataend = datalimit - _step + minstep;
step[0] = _step; step[1] = esz;
}
else
{
data = datastart = dataend = 0;
Mat(m->rows, m->cols, m->type, m->data.ptr, m->step).copyTo(*this);
}
}
template<typename _Tp> inline Mat::Mat(const vector<_Tp>& vec, bool copyData)
: flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG),
dims(2), rows((int)vec.size()), cols(1), data(0), refcount(0),
@@ -338,8 +319,9 @@ inline Mat Mat::colRange(const Range& r) const
inline Mat Mat::diag(const Mat& d)
{
CV_Assert( d.cols == 1 );
Mat m(d.rows, d.rows, d.type(), Scalar(0)), md = m.diag();
CV_Assert( d.cols == 1 || d.rows == 1 );
int len = d.rows + d.cols - 1;
Mat m(len, len, d.type(), Scalar(0)), md = m.diag();
d.copyTo(md);
return m;
}
@@ -969,9 +951,6 @@ template<typename _Tp> inline int Mat_<_Tp>::channels() const
template<typename _Tp> inline size_t Mat_<_Tp>::stepT(int i) const { return step.p[i]/elemSize(); }
template<typename _Tp> inline size_t Mat_<_Tp>::step1(int i) const { return step.p[i]/elemSize1(); }
template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::reshape(int _rows) const
{ return Mat_<_Tp>(Mat::reshape(0,_rows)); }
template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright )
{ return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright)); }

View File

@@ -2277,7 +2277,7 @@ public:
{ set((_Tp*)&vec.val[0], n, true); }
Vector(const std::vector<_Tp>& vec, bool _copyData=false)
{ set((_Tp*)&vec[0], vec.size(), _copyData); }
{ set(!vec.empty() ? (_Tp*)&vec[0] : 0, vec.size(), _copyData); }
Vector(const Vector& d) { *this = d; }
@@ -2445,14 +2445,17 @@ dot(const Vector<_Tp>& v1, const Vector<_Tp>& v2)
assert(v1.size() == v2.size());
_Tw s = 0;
const _Tp *ptr1 = &v1[0], *ptr2 = &v2[0];
#if CV_ENABLE_UNROLLED
for(; i <= n - 4; i += 4 )
s += (_Tw)ptr1[i]*ptr2[i] + (_Tw)ptr1[i+1]*ptr2[i+1] +
(_Tw)ptr1[i+2]*ptr2[i+2] + (_Tw)ptr1[i+3]*ptr2[i+3];
#endif
for( ; i < n; i++ )
s += (_Tw)ptr1[i]*ptr2[i];
if( n > 0 )
{
const _Tp *ptr1 = &v1[0], *ptr2 = &v2[0];
#if CV_ENABLE_UNROLLED
for(; i <= n - 4; i += 4 )
s += (_Tw)ptr1[i]*ptr2[i] + (_Tw)ptr1[i+1]*ptr2[i+1] +
(_Tw)ptr1[i+2]*ptr2[i+2] + (_Tw)ptr1[i+3]*ptr2[i+3];
#endif
for( ; i < n; i++ )
s += (_Tw)ptr1[i]*ptr2[i];
}
return s;
}
@@ -2834,29 +2837,27 @@ public:
{
int _fmt = DataType<_Tp>::fmt;
char fmt[] = { (char)((_fmt>>8)+'1'), (char)_fmt, '\0' };
fs->writeRaw( string(fmt), (uchar*)&vec[0], vec.size()*sizeof(_Tp) );
fs->writeRaw( string(fmt), !vec.empty() ? (uchar*)&vec[0] : 0, vec.size()*sizeof(_Tp) );
}
FileStorage* fs;
};
template<typename _Tp> static inline void write( FileStorage& fs, const vector<_Tp>& vec )
{
VecWriterProxy<_Tp, DataType<_Tp>::fmt != 0> w(&fs);
w(vec);
}
template<typename _Tp> static inline FileStorage&
operator << ( FileStorage& fs, const vector<_Tp>& vec )
template<typename _Tp> static inline void write( FileStorage& fs, const string& name,
const vector<_Tp>& vec )
{
VecWriterProxy<_Tp, DataType<_Tp>::generic_type == 0> w(&fs);
w(vec);
return fs;
}
WriteStructContext ws(fs, name, CV_NODE_SEQ+(DataType<_Tp>::fmt != 0 ? CV_NODE_FLOW : 0));
write(fs, vec);
}
CV_EXPORTS_W void write( FileStorage& fs, const string& name, const Mat& value );
CV_EXPORTS void write( FileStorage& fs, const string& name, const SparseMat& value );
template<typename _Tp> static inline FileStorage& operator << (FileStorage& fs, const _Tp& value)
{
if( !fs.isOpened() )
@@ -2893,7 +2894,7 @@ inline size_t FileNode::size() const
{
int t = type();
return t == MAP ? ((CvSet*)node->data.map)->active_count :
t == SEQ ? node->data.seq->total : node != 0;
t == SEQ ? node->data.seq->total : (size_t)!isNone();
}
inline CvFileNode* FileNode::operator *() { return (CvFileNode*)node; }
@@ -2956,7 +2957,7 @@ static inline void read(const FileNode& node, string& value, const string& defau
}
CV_EXPORTS_W void read(const FileNode& node, Mat& mat, const Mat& default_mat=Mat() );
CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat=SparseMat() );
CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat=SparseMat() );
inline FileNode::operator int() const
{
@@ -3011,10 +3012,10 @@ public:
size_t remaining = it->remaining, cn = DataType<_Tp>::channels;
int _fmt = DataType<_Tp>::fmt;
char fmt[] = { (char)((_fmt>>8)+'1'), (char)_fmt, '\0' };
size_t remaining1 = remaining/cn;
count = count < remaining1 ? count : remaining1;
size_t remaining1 = remaining/cn;
count = count < remaining1 ? count : remaining1;
vec.resize(count);
it->readRaw( string(fmt), (uchar*)&vec[0], count*sizeof(_Tp) );
it->readRaw( string(fmt), !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp) );
}
FileNodeIterator* it;
};
@@ -3027,9 +3028,15 @@ read( FileNodeIterator& it, vector<_Tp>& vec, size_t maxCount=(size_t)INT_MAX )
}
template<typename _Tp> static inline void
read( FileNode& node, vector<_Tp>& vec, const vector<_Tp>& default_value=vector<_Tp>() )
read( const FileNode& node, vector<_Tp>& vec, const vector<_Tp>& default_value=vector<_Tp>() )
{
read( node.begin(), vec );
if(!node.node)
vec = default_value;
else
{
FileNodeIterator it = node.begin();
read( it, vec );
}
}
inline FileNodeIterator FileNode::begin() const

View File

@@ -32,5 +32,5 @@ PERF_TEST_P( Size_DepthSrc_DepthDst_Channels_alpha, convertTo,
TEST_CYCLE() src.convertTo(dst, depthDst, alpha);
SANITY_CHECK(dst);
SANITY_CHECK(dst, 1e-12);
}

View File

@@ -32,5 +32,5 @@ PERF_TEST_P( Size_SrcDepth_DstChannels, merge,
Mat dst;
TEST_CYCLE() merge( (vector<Mat> &)mv, dst );
SANITY_CHECK(dst);
SANITY_CHECK(dst, 1e-12);
}

View File

@@ -29,5 +29,5 @@ PERF_TEST_P( Size_Depth_Channels, split,
TEST_CYCLE() split(m, (vector<Mat>&)mv);
SANITY_CHECK(mv);
SANITY_CHECK(mv, 1e-12);
}

View File

@@ -149,17 +149,21 @@ struct CV_EXPORTS AlgorithmInfoData
};
static sorted_vector<string, Algorithm::Constructor> alglist;
static sorted_vector<string, Algorithm::Constructor>& alglist()
{
static sorted_vector<string, Algorithm::Constructor> alglist_var;
return alglist_var;
}
void Algorithm::getList(vector<string>& algorithms)
{
alglist.get_keys(algorithms);
alglist().get_keys(algorithms);
}
Ptr<Algorithm> Algorithm::_create(const string& name)
{
Algorithm::Constructor c = 0;
if( !alglist.find(name, c) )
if( !alglist().find(name, c) )
return Ptr<Algorithm>();
return c();
}
@@ -202,6 +206,11 @@ void Algorithm::set(const string& name, const Mat& value)
info()->set(this, name.c_str(), ParamType<Mat>::type, &value);
}
void Algorithm::set(const string& name, const vector<Mat>& value)
{
info()->set(this, name.c_str(), ParamType<vector<Mat> >::type, &value);
}
void Algorithm::set(const string& name, const Ptr<Algorithm>& value)
{
info()->set(this, name.c_str(), ParamType<Algorithm>::type, &value);
@@ -232,6 +241,11 @@ void Algorithm::set(const char* name, const Mat& value)
info()->set(this, name, ParamType<Mat>::type, &value);
}
void Algorithm::set(const char* name, const vector<Mat>& value)
{
info()->set(this, name, ParamType<vector<Mat> >::type, &value);
}
void Algorithm::set(const char* name, const Ptr<Algorithm>& value)
{
info()->set(this, name, ParamType<Algorithm>::type, &value);
@@ -272,7 +286,7 @@ AlgorithmInfo::AlgorithmInfo(const string& _name, Algorithm::Constructor create)
{
data = new AlgorithmInfoData;
data->_name = _name;
alglist.add(_name, create);
alglist().add(_name, create);
}
AlgorithmInfo::~AlgorithmInfo()
@@ -298,6 +312,8 @@ void AlgorithmInfo::write(const Algorithm* algo, FileStorage& fs) const
cv::write(fs, pname, algo->get<string>(pname));
else if( p.type == Param::MAT )
cv::write(fs, pname, algo->get<Mat>(pname));
else if( p.type == Param::MAT_VECTOR )
cv::write(fs, pname, algo->get<vector<Mat> >(pname));
else if( p.type == Param::ALGORITHM )
{
WriteStructContext ws(fs, pname, CV_NODE_MAP);
@@ -317,7 +333,7 @@ void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
{
const Param& p = data->params.vec[i].second;
const string& pname = data->params.vec[i].first;
FileNode n = fn[pname];
const FileNode n = fn[pname];
if( n.empty() )
continue;
if( p.type == Param::INT )
@@ -331,9 +347,15 @@ void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
else if( p.type == Param::MAT )
{
Mat m;
cv::read(fn, m);
cv::read(n, m);
algo->set(pname, m);
}
else if( p.type == Param::MAT_VECTOR )
{
vector<Mat> mv;
cv::read(n, mv);
algo->set(pname, mv);
}
else if( p.type == Param::ALGORITHM )
{
Ptr<Algorithm> nestedAlgo = Algorithm::_create((string)n["name"]);
@@ -358,6 +380,7 @@ union GetSetParam
double (Algorithm::*get_double)() const;
string (Algorithm::*get_string)() const;
Mat (Algorithm::*get_mat)() const;
vector<Mat> (Algorithm::*get_mat_vector)() const;
Ptr<Algorithm> (Algorithm::*get_algo)() const;
void (Algorithm::*set_int)(int);
@@ -365,6 +388,7 @@ union GetSetParam
void (Algorithm::*set_double)(double);
void (Algorithm::*set_string)(const string&);
void (Algorithm::*set_mat)(const Mat&);
void (Algorithm::*set_mat_vector)(const vector<Mat>&);
void (Algorithm::*set_algo)(const Ptr<Algorithm>&);
};
@@ -436,6 +460,16 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
else
*(Mat*)((uchar*)algo + p->offset) = val;
}
else if( argType == Param::MAT_VECTOR )
{
CV_Assert( p->type == Param::MAT_VECTOR );
const vector<Mat>& val = *(const vector<Mat>*)value;
if( p->setter )
(algo->*f.set_mat_vector)(val);
else
*(vector<Mat>*)((uchar*)algo + p->offset) = val;
}
else if( argType == Param::ALGORITHM )
{
CV_Assert( p->type == Param::ALGORITHM );
@@ -505,6 +539,13 @@ void AlgorithmInfo::get(const Algorithm* algo, const char* name, int argType, vo
*(Mat*)value = p->getter ? (algo->*f.get_mat)() :
*(Mat*)((uchar*)algo + p->offset);
}
else if( argType == Param::MAT_VECTOR )
{
CV_Assert( p->type == Param::MAT_VECTOR );
*(vector<Mat>*)value = p->getter ? (algo->*f.get_mat_vector)() :
*(vector<Mat>*)((uchar*)algo + p->offset);
}
else if( argType == Param::ALGORITHM )
{
CV_Assert( p->type == Param::ALGORITHM );
@@ -548,7 +589,8 @@ void AlgorithmInfo::addParam_(Algorithm& algo, const char* name, int argType,
{
CV_Assert( argType == Param::INT || argType == Param::BOOLEAN ||
argType == Param::REAL || argType == Param::STRING ||
argType == Param::MAT || argType == Param::ALGORITHM );
argType == Param::MAT || argType == Param::MAT_VECTOR ||
argType == Param::ALGORITHM );
data->params.add(string(name), Param(argType, readOnly,
(int)((size_t)value - (size_t)(void*)&algo),
getter, setter, help));
@@ -604,6 +646,16 @@ void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
addParam_(algo, name, ParamType<Mat>::type, &value, readOnly,
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
}
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
vector<Mat>& value, bool readOnly,
vector<Mat> (Algorithm::*getter)(),
void (Algorithm::*setter)(const vector<Mat>&),
const string& help)
{
addParam_(algo, name, ParamType<vector<Mat> >::type, &value, readOnly,
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
}
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
Ptr<Algorithm>& value, bool readOnly,

View File

@@ -47,6 +47,7 @@ namespace cv
// On Win64 optimized versions of DFT and DCT fail the tests (fixed in VS2010)
#if defined _MSC_VER && !defined CV_ICC && defined _M_X64 && _MSC_VER < 1600
#pragma optimize("", off)
#pragma warning( disable : 4748 )
#endif
/****************************************************************************************\

View File

@@ -2032,8 +2032,9 @@ template<> struct mat_type_assotiations<CV_32S>
static const type max_allowable = INT_MAX;
};
// inclusive maxVal !!!
template<int depth>
bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value)
bool checkIntegerRange(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value)
{
typedef mat_type_assotiations<depth> type_ass;
@@ -2041,7 +2042,7 @@ bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double
{
return true;
}
else if (minVal >= type_ass::max_allowable || maxVal <= type_ass::min_allowable || maxVal <= minVal)
else if (minVal > type_ass::max_allowable || maxVal < type_ass::min_allowable || maxVal < minVal)
{
bad_pt = cv::Point(0,0);
return false;
@@ -2051,7 +2052,7 @@ bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double
for (int j = 0; j < as_one_channel.rows; ++j)
for (int i = 0; i < as_one_channel.cols; ++i)
{
if (as_one_channel.at<typename type_ass::type>(j ,i) <= minVal || as_one_channel.at<typename type_ass::type>(j ,i) >= maxVal)
if (as_one_channel.at<typename type_ass::type>(j ,i) < minVal || as_one_channel.at<typename type_ass::type>(j ,i) > maxVal)
{
bad_pt.y = j ;
bad_pt.x = i % src.channels();
@@ -2064,15 +2065,15 @@ bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double
return true;
}
typedef bool (*check_pange_function)(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value);
typedef bool (*check_range_function)(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value);
check_pange_function check_range_functions[] =
check_range_function check_range_functions[] =
{
&chackIntegerRang<CV_8U>,
&chackIntegerRang<CV_8S>,
&chackIntegerRang<CV_16U>,
&chackIntegerRang<CV_16S>,
&chackIntegerRang<CV_32S>
&checkIntegerRange<CV_8U>,
&checkIntegerRange<CV_8S>,
&checkIntegerRange<CV_16U>,
&checkIntegerRange<CV_16S>,
&checkIntegerRange<CV_32S>
};
bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double maxVal)
@@ -2102,8 +2103,9 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma
if (depth < CV_32F)
{
int minVali = cvFloor(minVal);
int maxVali = cvCeil(maxVal);
// see "Bug #1784"
int minVali = minVal<(-INT_MAX - 1) ? (-INT_MAX - 1) : cvFloor(minVal);
int maxVali = maxVal>INT_MAX ? INT_MAX : cvCeil(maxVal) - 1; // checkIntegerRang() use inclusive maxVal
(check_range_functions[depth])(src, badPt, minVali, maxVali, badValue);
}
@@ -2487,7 +2489,7 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters )
for( i = 0; i < n; i++ )
{
p = roots[i];
C num = coeffs[n], denom = 1;
C num = coeffs[n], denom = coeffs[n];
for( j = 0; j < n; j++ )
{
num = num*p + coeffs[n-j-1];

View File

@@ -2098,7 +2098,7 @@ void cv::calcCovarMatrix( const Mat* data, int nsamples, Mat& covar, Mat& _mean,
{
CV_Assert( data && nsamples > 0 );
Size size = data[0].size();
int sz = size.width*size.height, esz = (int)data[0].elemSize();
int sz = size.width * size.height, esz = (int)data[0].elemSize();
int type = data[0].type();
Mat mean;
ctype = std::max(std::max(CV_MAT_DEPTH(ctype >= 0 ? ctype : type), _mean.depth()), CV_32F);
@@ -2116,6 +2116,7 @@ void cv::calcCovarMatrix( const Mat* data, int nsamples, Mat& covar, Mat& _mean,
}
Mat _data(nsamples, sz, type);
for( int i = 0; i < nsamples; i++ )
{
CV_Assert( data[i].size() == size && data[i].type() == type );
@@ -2135,6 +2136,55 @@ void cv::calcCovarMatrix( const Mat* data, int nsamples, Mat& covar, Mat& _mean,
void cv::calcCovarMatrix( InputArray _data, OutputArray _covar, InputOutputArray _mean, int flags, int ctype )
{
if(_data.kind() == _InputArray::STD_VECTOR_MAT)
{
std::vector<cv::Mat> src;
_data.getMatVector(src);
CV_Assert( src.size() > 0 );
Size size = src[0].size();
int type = src[0].type();
ctype = std::max(std::max(CV_MAT_DEPTH(ctype >= 0 ? ctype : type), _mean.depth()), CV_32F);
Mat _data(static_cast<int>(src.size()), size.area(), type);
int i = 0;
for(vector<cv::Mat>::iterator each = src.begin(); each != src.end(); each++, i++ )
{
CV_Assert( (*each).size() == size && (*each).type() == type );
Mat dataRow(size.height, size.width, type, _data.ptr(i));
(*each).copyTo(dataRow);
}
Mat mean;
if( (flags & CV_COVAR_USE_AVG) != 0 )
{
CV_Assert( _mean.size() == size );
if( mean.type() != ctype )
{
mean = _mean.getMat();
_mean.create(mean.size(), ctype);
Mat tmp = _mean.getMat();
mean.convertTo(tmp, ctype);
mean = tmp;
}
mean = _mean.getMat().reshape(1, 1);
}
calcCovarMatrix( _data, _covar, mean, (flags & ~(CV_COVAR_ROWS|CV_COVAR_COLS)) | CV_COVAR_ROWS, ctype );
if( (flags & CV_COVAR_USE_AVG) == 0 )
{
mean = mean.reshape(1, size.height);
mean.copyTo(_mean);
}
return;
}
Mat data = _data.getMat(), mean;
CV_Assert( ((flags & CV_COVAR_ROWS) != 0) ^ ((flags & CV_COVAR_COLS) != 0) );
bool takeRows = (flags & CV_COVAR_ROWS) != 0;

View File

@@ -262,10 +262,9 @@ void Mat::deallocate()
}
Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange)
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange) : size(&rows)
{
initEmpty();
CV_Assert( m.dims >= 2 );
if( m.dims > 2 )
{
@@ -336,21 +335,19 @@ Mat::Mat(const Mat& m, const Rect& roi)
}
Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _steps)
: flags(MAGIC_VAL|CV_MAT_TYPE(_type)), dims(0),
rows(0), cols(0), data((uchar*)_data), refcount(0),
datastart((uchar*)_data), dataend((uchar*)_data), datalimit((uchar*)_data),
allocator(0), size(&rows)
Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _steps) : size(&rows)
{
initEmpty();
flags |= CV_MAT_TYPE(_type);
data = datastart = (uchar*)_data;
setSize(*this, _dims, _sizes, _steps, true);
finalizeHdr(*this);
}
Mat::Mat(const Mat& m, const Range* ranges)
: flags(m.flags), dims(0), rows(0), cols(0), data(0), refcount(0),
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
Mat::Mat(const Mat& m, const Range* ranges) : size(&rows)
{
initEmpty();
int i, d = m.dims;
CV_Assert(ranges);
@@ -374,12 +371,13 @@ Mat::Mat(const Mat& m, const Range* ranges)
}
Mat::Mat(const CvMatND* m, bool copyData)
: flags(MAGIC_VAL|CV_MAT_TYPE(m->type)), dims(0), rows(0), cols(0),
data((uchar*)m->data.ptr), refcount(0),
datastart((uchar*)m->data.ptr), allocator(0),
size(&rows)
Mat::Mat(const CvMatND* m, bool copyData) : size(&rows)
{
initEmpty();
if( !m )
return;
data = datastart = m->data.ptr;
flags |= CV_MAT_TYPE(m->type);
int _sizes[CV_MAX_DIM];
size_t _steps[CV_MAX_DIM];
@@ -434,12 +432,45 @@ Mat Mat::diag(int d) const
return m;
}
Mat::Mat(const IplImage* img, bool copyData)
: flags(MAGIC_VAL), dims(2), rows(0), cols(0),
data(0), refcount(0), datastart(0), dataend(0), allocator(0), size(&rows)
Mat::Mat(const CvMat* m, bool copyData) : size(&rows)
{
initEmpty();
if( !m )
return;
if( !copyData )
{
flags = MAGIC_VAL + (m->type & (CV_MAT_TYPE_MASK|CV_MAT_CONT_FLAG));
dims = 2;
rows = m->rows;
cols = m->cols;
data = datastart = m->data.ptr;
size_t esz = CV_ELEM_SIZE(m->type), minstep = cols*esz, _step = m->step;
if( _step == 0 )
_step = minstep;
datalimit = datastart + _step*rows;
dataend = datalimit - _step + minstep;
step[0] = _step; step[1] = esz;
}
else
{
data = datastart = dataend = 0;
Mat(m->rows, m->cols, m->type, m->data.ptr, m->step).copyTo(*this);
}
}
Mat::Mat(const IplImage* img, bool copyData) : size(&rows)
{
initEmpty();
if( !img )
return;
dims = 2;
CV_DbgAssert(CV_IS_IMAGE(img) && img->imageData != 0);
int depth = IPL2CV_DEPTH(img->depth);
@@ -2428,8 +2459,9 @@ double cv::kmeans( InputArray _data, int K,
{
const int SPP_TRIALS = 3;
Mat data = _data.getMat();
int N = data.rows > 1 ? data.rows : data.cols;
int dims = (data.rows > 1 ? data.cols : 1)*data.channels();
bool isrow = data.rows == 1 && data.channels() > 1;
int N = !isrow ? data.rows : data.cols;
int dims = (!isrow ? data.cols : 1)*data.channels();
int type = data.depth();
attempts = std::max(attempts, 1);
@@ -2458,7 +2490,7 @@ double cv::kmeans( InputArray _data, int K,
}
int* labels = _labels.ptr<int>();
Mat centers(K, dims, type), old_centers(K, dims, type);
Mat centers(K, dims, type), old_centers(K, dims, type), temp(1, dims, type);
vector<int> counters(K);
vector<Vec2f> _box(dims);
Vec2f* box = &_box[0];
@@ -2502,7 +2534,7 @@ double cv::kmeans( InputArray _data, int K,
for( a = 0; a < attempts; a++ )
{
double max_center_shift = DBL_MAX;
for( iter = 0; iter < criteria.maxCount && max_center_shift > criteria.epsilon; iter++ )
for( iter = 0;; )
{
swap(centers, old_centers);
@@ -2579,13 +2611,17 @@ double cv::kmeans( InputArray _data, int K,
int farthest_i = -1;
float* new_center = centers.ptr<float>(k);
float* old_center = centers.ptr<float>(max_k);
float* _old_center = temp.ptr<float>(); // normalized
float scale = 1.f/counters[max_k];
for( j = 0; j < dims; j++ )
_old_center[j] = old_center[j]*scale;
for( i = 0; i < N; i++ )
{
if( labels[i] != max_k )
continue;
sample = data.ptr<float>(i);
double dist = normL2Sqr_(sample, old_center, dims);
double dist = normL2Sqr_(sample, _old_center, dims);
if( max_dist <= dist )
{
@@ -2596,6 +2632,7 @@ double cv::kmeans( InputArray _data, int K,
counters[max_k]--;
counters[k]++;
labels[farthest_i] = k;
sample = data.ptr<float>(farthest_i);
for( j = 0; j < dims; j++ )
@@ -2627,6 +2664,9 @@ double cv::kmeans( InputArray _data, int K,
}
}
}
if( ++iter == MAX(criteria.maxCount, 2) || max_center_shift <= criteria.epsilon )
break;
// assign labels
compactness = 0;

View File

@@ -2987,9 +2987,6 @@ cvWriteRawData( CvFileStorage* fs, const void* _data, int len, const char* dt )
CV_CHECK_OUTPUT_FILE_STORAGE( fs );
if( !data0 )
CV_Error( CV_StsNullPtr, "Null data pointer" );
if( len < 0 )
CV_Error( CV_StsOutOfRange, "Negative number of elements" );
@@ -2997,6 +2994,9 @@ cvWriteRawData( CvFileStorage* fs, const void* _data, int len, const char* dt )
if( !len )
return;
if( !data0 )
CV_Error( CV_StsNullPtr, "Null data pointer" );
if( fmt_pair_count == 1 )
{
@@ -3457,6 +3457,8 @@ icvReadMat( CvFileStorage* fs, CvFileNode* node )
mat = cvCreateMat( rows, cols, elem_type );
cvReadRawData( fs, data, mat->data.ptr, dt );
}
else if( rows == 0 && cols == 0 )
mat = cvCreateMatHeader( 0, 1, elem_type );
else
mat = cvCreateMatHeader( rows, cols, elem_type );
@@ -5195,7 +5197,7 @@ FileNodeIterator::FileNodeIterator()
FileNodeIterator::FileNodeIterator(const CvFileStorage* _fs,
const CvFileNode* _node, size_t _ofs)
{
if( _fs && _node )
if( _fs && _node && CV_NODE_TYPE(_node->tag) != CV_NODE_NONE )
{
int node_type = _node->tag & FileNode::TYPE_MASK;
fs = _fs;
@@ -5358,7 +5360,7 @@ void write( FileStorage& fs, const string& name, const SparseMat& value )
Ptr<CvSparseMat> mat = (CvSparseMat*)value;
cvWrite( *fs, name.size() ? name.c_str() : 0, mat );
}
WriteStructContext::WriteStructContext(FileStorage& _fs, const string& name,
int flags, const string& typeName) : fs(&_fs)

View File

@@ -1605,25 +1605,20 @@ struct BatchDistInvoker
// we handle both CV_32S and CV_32F cases with a single branch
int* distptr = (int*)dist->ptr(i);
int k, k0, k0_, j;
for( k0 = 0; k0 < K; k0++ )
if( nidxptr[k0] < 0 )
break;
k0_ = std::max(k0, 1);
int j, k;
for( j = 0; j < src2->rows; j++ )
{
int d = bufptr[j];
if( d < distptr[k0_-1] )
if( d < distptr[K-1] )
{
for( k = std::min(k0-1, K-2); k >= 0 && distptr[k] > d; k-- )
for( k = K-2; k >= 0 && distptr[k] > d; k-- )
{
nidxptr[k+1] = nidxptr[k];
distptr[k+1] = distptr[k];
}
nidxptr[k+1] = j + update;
distptr[k+1] = d;
k0_ = k0 = std::min(k0 + 1, K);
}
}
}

View File

@@ -374,6 +374,46 @@ int getThreadNum(void)
#endif
}
#if ANDROID
static inline int getNumberOfCPUsImpl()
{
FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r");
if(!cpuPossible)
return 1;
char buf[2000]; //big enough for 1000 CPUs in worst possible configuration
char* pbuf = fgets(buf, sizeof(buf), cpuPossible);
fclose(cpuPossible);
if(!pbuf)
return 1;
//parse string of form "0-1,3,5-7,10,13-15"
int cpusAvailable = 0;
while(*pbuf)
{
const char* pos = pbuf;
bool range = false;
while(*pbuf && *pbuf != ',')
{
if(*pbuf == '-') range = true;
++pbuf;
}
if(*pbuf) *pbuf++ = 0;
if(!range)
++cpusAvailable;
else
{
int rstart = 0, rend = 0;
sscanf(pos, "%d-%d", &rstart, &rend);
cpusAvailable += rend - rstart + 1;
}
}
return cpusAvailable ? cpusAvailable : 1;
}
#endif
int getNumberOfCPUs(void)
{
#if defined WIN32 || defined _WIN32
@@ -381,6 +421,10 @@ int getNumberOfCPUs(void)
GetSystemInfo( &sysinfo );
return (int)sysinfo.dwNumberOfProcessors;
#elif ANDROID
static int ncpus = getNumberOfCPUsImpl();
printf("CPUS= %d\n", ncpus);
return ncpus;
#elif defined __linux__
return (int)sysconf( _SC_NPROCESSORS_ONLN );
#elif defined __APPLE__
@@ -410,6 +454,14 @@ int getNumberOfCPUs(void)
#endif
}
const std::string& getBuildInformation()
{
static std::string build_info =
#include "version_string.inc"
;
return build_info;
}
string format( const char* fmt, ... )
{
char buf[1 << 16];

View File

@@ -1437,6 +1437,9 @@ protected:
Mat mask1;
Mat c, d;
rng.fill(a, RNG::UNIFORM, 0, 100);
rng.fill(b, RNG::UNIFORM, 0, 100);
// [-2,2) range means that the each generated random number
// will be one of -2, -1, 0, 1. Saturated to [0,255], it will become
// 0, 0, 0, 1 => the mask will be filled by ~25%.

View File

@@ -42,7 +42,7 @@
#include "test_precomp.hpp"
#include <time.h>
#include <limits>
using namespace cv;
using namespace std;
@@ -82,7 +82,7 @@ private:
void print_information(int right, int result);
};
CV_CountNonZeroTest::CV_CountNonZeroTest(): eps_32(1e-8f), eps_64(1e-16f), src(Mat()), current_type(-1) {}
CV_CountNonZeroTest::CV_CountNonZeroTest(): eps_32(std::numeric_limits<float>::min()), eps_64(std::numeric_limits<double>::min()), src(Mat()), current_type(-1) {}
CV_CountNonZeroTest::~CV_CountNonZeroTest() {}
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type)
@@ -252,4 +252,4 @@ void CV_CountNonZeroTest::run(int)
}
}
// TEST (Core_CountNonZero, accuracy) { CV_CountNonZeroTest test; test.safe_run(); }
TEST (Core_CountNonZero, accuracy) { CV_CountNonZeroTest test; test.safe_run(); }

View File

@@ -146,7 +146,6 @@ void Core_EigenTest_Scalar_32::run(int)
float value = cv::randu<float>();
cv::Mat src(1, 1, CV_32FC1, Scalar::all((float)value));
test_values(src);
src.~Mat();
}
}
@@ -158,7 +157,6 @@ void Core_EigenTest_Scalar_64::run(int)
float value = cv::randu<float>();
cv::Mat src(1, 1, CV_64FC1, Scalar::all((double)value));
test_values(src);
src.~Mat();
}
}
@@ -401,8 +399,6 @@ bool Core_EigenTest::check_full(int type)
else src.at<double>(k, j) = src.at<double>(j, k) = cv::randu<double>();
if (!test_values(src)) return false;
src.~Mat();
}
return true;

View File

@@ -377,6 +377,53 @@ protected:
TEST(Core_InputOutput, write_read_consistency) { Core_IOTest test; test.safe_run(); }
class CV_MiscIOTest : public cvtest::BaseTest
{
public:
CV_MiscIOTest() {}
~CV_MiscIOTest() {}
protected:
void run(int)
{
try
{
FileStorage fs("test.xml", FileStorage::WRITE);
vector<int> mi, mi2, mi3, mi4;
vector<Mat> mv, mv2, mv3, mv4;
Mat m(10, 9, CV_32F);
Mat empty;
randu(m, 0, 1);
mi3.push_back(5);
mv3.push_back(m);
fs << "mi" << mi;
fs << "mv" << mv;
fs << "mi3" << mi3;
fs << "mv3" << mv3;
fs << "empty" << empty;
fs.release();
fs.open("test.xml", FileStorage::READ);
fs["mi"] >> mi2;
fs["mv"] >> mv2;
fs["mi3"] >> mi4;
fs["mv3"] >> mv4;
fs["empty"] >> empty;
CV_Assert( mi2.empty() );
CV_Assert( mv2.empty() );
CV_Assert( norm(mi3, mi4, CV_C) == 0 );
CV_Assert( mv4.size() == 1 );
double n = norm(mv3[0], mv4[0], CV_C);
CV_Assert( n == 0 );
}
catch(...)
{
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
}
}
};
TEST(Core_InputOutput, misc) { CV_MiscIOTest test; test.safe_run(); }
/*class CV_BigMatrixIOTest : public cvtest::BaseTest
{
public:

View File

@@ -10,7 +10,7 @@ public:
Core_ReduceTest() {};
protected:
void run( int);
int checkOp( const Mat& src, int dstType, int opType, const Mat& opRes, int dim, double eps );
int checkOp( const Mat& src, int dstType, int opType, const Mat& opRes, int dim );
int checkCase( int srcType, int dstType, int dim, Size sz );
int checkDim( int dim, Size sz );
int checkSize( Size sz );
@@ -80,7 +80,7 @@ void getMatTypeStr( int type, string& str)
type == CV_64FC1 ? "CV_64FC1" : "unsupported matrix type";
}
int Core_ReduceTest::checkOp( const Mat& src, int dstType, int opType, const Mat& opRes, int dim, double eps )
int Core_ReduceTest::checkOp( const Mat& src, int dstType, int opType, const Mat& opRes, int dim )
{
int srcType = src.type();
bool support = false;
@@ -117,12 +117,30 @@ int Core_ReduceTest::checkOp( const Mat& src, int dstType, int opType, const Mat
}
if( !support )
return cvtest::TS::OK;
double eps = 0.0;
if ( opType == CV_REDUCE_SUM || opType == CV_REDUCE_AVG )
{
if ( dstType == CV_32F )
eps = 1.e-5;
else if( dstType == CV_64F )
eps = 1.e-8;
else if ( dstType == CV_32S )
eps = 0.6;
}
assert( opRes.type() == CV_64FC1 );
Mat _dst, dst;
Mat _dst, dst, diff;
reduce( src, _dst, dim, opType, dstType );
_dst.convertTo( dst, CV_64FC1 );
if( norm( opRes, dst, NORM_INF ) > eps )
absdiff( opRes,dst,diff );
bool check = false;
if (dstType == CV_32F || dstType == CV_64F)
check = countNonZero(diff>eps*dst) > 0;
else
check = countNonZero(diff>eps) > 0;
if( check )
{
char msg[100];
const char* opTypeStr = opType == CV_REDUCE_SUM ? "CV_REDUCE_SUM" :
@@ -168,21 +186,19 @@ int Core_ReduceTest::checkCase( int srcType, int dstType, int dim, Size sz )
assert( 0 );
// 1. sum
tempCode = checkOp( src, dstType, CV_REDUCE_SUM, sum, dim,
srcType == CV_32FC1 && dstType == CV_32FC1 ? 0.05 : FLT_EPSILON );
tempCode = checkOp( src, dstType, CV_REDUCE_SUM, sum, dim );
code = tempCode != cvtest::TS::OK ? tempCode : code;
// 2. avg
tempCode = checkOp( src, dstType, CV_REDUCE_AVG, avg, dim,
dstType == CV_32SC1 ? 0.6 : 0.00007 );
tempCode = checkOp( src, dstType, CV_REDUCE_AVG, avg, dim );
code = tempCode != cvtest::TS::OK ? tempCode : code;
// 3. max
tempCode = checkOp( src, dstType, CV_REDUCE_MAX, max, dim, FLT_EPSILON );
tempCode = checkOp( src, dstType, CV_REDUCE_MAX, max, dim );
code = tempCode != cvtest::TS::OK ? tempCode : code;
// 4. min
tempCode = checkOp( src, dstType, CV_REDUCE_MIN, min, dim, FLT_EPSILON );
tempCode = checkOp( src, dstType, CV_REDUCE_MIN, min, dim );
code = tempCode != cvtest::TS::OK ? tempCode : code;
return code;

View File

@@ -2347,6 +2347,41 @@ void Core_SolvePolyTest::run( int )
}
}
class Core_CheckRange_Empty : public cvtest::BaseTest
{
public:
Core_CheckRange_Empty(){}
~Core_CheckRange_Empty(){}
protected:
virtual void run( int start_from );
};
void Core_CheckRange_Empty::run( int )
{
cv::Mat m;
ASSERT_TRUE( cv::checkRange(m) );
}
TEST(Core_CheckRange_Empty, accuracy) { Core_CheckRange_Empty test; test.safe_run(); }
class Core_CheckRange_INT_MAX : public cvtest::BaseTest
{
public:
Core_CheckRange_INT_MAX(){}
~Core_CheckRange_INT_MAX(){}
protected:
virtual void run( int start_from );
};
void Core_CheckRange_INT_MAX::run( int )
{
cv::Mat m(3, 3, CV_32SC1, cv::Scalar(INT_MAX));
ASSERT_FALSE( cv::checkRange(m, true, 0, 0, INT_MAX) );
ASSERT_TRUE( cv::checkRange(m) );
}
TEST(Core_CheckRange_INT_MAX, accuracy) { Core_CheckRange_INT_MAX test; test.safe_run(); }
template <typename T> class Core_CheckRange : public testing::Test {};
TYPED_TEST_CASE_P(Core_CheckRange);
@@ -2402,7 +2437,17 @@ TYPED_TEST_P(Core_CheckRange, Bounds)
delete bad_pt;
}
REGISTER_TYPED_TEST_CASE_P(Core_CheckRange, Negative, Positive, Bounds);
TYPED_TEST_P(Core_CheckRange, Zero)
{
double min_bound = 0.0;
double max_bound = 0.1;
cv::Mat src = cv::Mat::zeros(3,3, cv::DataDepth<TypeParam>::value);
ASSERT_TRUE( checkRange(src, true, NULL, min_bound, max_bound) );
}
REGISTER_TYPED_TEST_CASE_P(Core_CheckRange, Negative, Positive, Bounds, Zero);
typedef ::testing::Types<signed char,unsigned char, signed short, unsigned short, signed int> mat_data_types;
INSTANTIATE_TYPED_TEST_CASE_P(Negative_Test, Core_CheckRange, mat_data_types);
@@ -2428,5 +2473,129 @@ TEST(Core_SolvePoly, accuracy) { Core_SolvePolyTest test; test.safe_run(); }
// TODO: eigenvv, invsqrt, cbrt, fastarctan, (round, floor, ceil(?)),
class CV_KMeansSingularTest : public cvtest::BaseTest
{
public:
CV_KMeansSingularTest() {}
~CV_KMeansSingularTest() {}
protected:
void run(int)
{
int i, iter = 0, N = 0, N0 = 0, K = 0, dims = 0;
Mat labels;
try
{
RNG& rng = theRNG();
const int MAX_DIM=5;
int MAX_POINTS = 100, maxIter = 100;
for( iter = 0; iter < maxIter; iter++ )
{
ts->update_context(this, iter, true);
dims = rng.uniform(1, MAX_DIM+1);
N = rng.uniform(1, MAX_POINTS+1);
N0 = rng.uniform(1, MAX(N/10, 2));
K = rng.uniform(1, N+1);
Mat data0(N0, dims, CV_32F);
rng.fill(data0, RNG::UNIFORM, -1, 1);
Mat data(N, dims, CV_32F);
for( i = 0; i < N; i++ )
data0.row(rng.uniform(0, N0)).copyTo(data.row(i));
kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0),
5, KMEANS_PP_CENTERS);
Mat hist(K, 1, CV_32S, Scalar(0));
for( i = 0; i < N; i++ )
{
int l = labels.at<int>(i);
CV_Assert(0 <= l && l < K);
hist.at<int>(l)++;
}
for( i = 0; i < K; i++ )
CV_Assert( hist.at<int>(i) != 0 );
}
}
catch(...)
{
ts->printf(cvtest::TS::LOG,
"context: iteration=%d, N=%d, N0=%d, K=%d\n",
iter, N, N0, K);
std::cout << labels << std::endl;
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
}
}
};
TEST(Core_KMeans, singular) { CV_KMeansSingularTest test; test.safe_run(); }
TEST(CovariationMatrixVectorOfMat, accuracy)
{
unsigned int col_problem_size = 8, row_problem_size = 8, vector_size = 16;
cv::Mat src(vector_size, col_problem_size * row_problem_size, CV_32F);
int singleMatFlags = CV_COVAR_ROWS;
cv::Mat gold;
cv::Mat goldMean;
cv::randu(src,cv::Scalar(-128), cv::Scalar(128));
cv::calcCovarMatrix(src,gold,goldMean,singleMatFlags,CV_32F);
std::vector<cv::Mat> srcVec;
for(size_t i = 0; i < vector_size; i++)
{
srcVec.push_back(src.row(static_cast<int>(i)).reshape(0,col_problem_size));
}
cv::Mat actual;
cv::Mat actualMean;
cv::calcCovarMatrix(srcVec, actual, actualMean,singleMatFlags,CV_32F);
cv::Mat diff;
cv::absdiff(gold, actual, diff);
cv::Scalar s = cv::sum(diff);
ASSERT_EQ(s.dot(s), 0.0);
cv::Mat meanDiff;
cv::absdiff(goldMean, actualMean.reshape(0,1), meanDiff);
cv::Scalar sDiff = cv::sum(meanDiff);
ASSERT_EQ(sDiff.dot(sDiff), 0.0);
}
TEST(CovariationMatrixVectorOfMatWithMean, accuracy)
{
unsigned int col_problem_size = 8, row_problem_size = 8, vector_size = 16;
cv::Mat src(vector_size, col_problem_size * row_problem_size, CV_32F);
int singleMatFlags = CV_COVAR_ROWS | CV_COVAR_USE_AVG;
cv::Mat gold;
cv::randu(src,cv::Scalar(-128), cv::Scalar(128));
cv::Mat goldMean;
cv::reduce(src,goldMean,0 ,CV_REDUCE_AVG, CV_32F);
cv::calcCovarMatrix(src,gold,goldMean,singleMatFlags,CV_32F);
std::vector<cv::Mat> srcVec;
for(size_t i = 0; i < vector_size; i++)
{
srcVec.push_back(src.row(static_cast<int>(i)).reshape(0,col_problem_size));
}
cv::Mat actual;
cv::Mat actualMean = goldMean.reshape(0, row_problem_size);
cv::calcCovarMatrix(srcVec, actual, actualMean,singleMatFlags,CV_32F);
cv::Mat diff;
cv::absdiff(gold, actual, diff);
cv::Scalar s = cv::sum(diff);
ASSERT_EQ(s.dot(s), 0.0);
cv::Mat meanDiff;
cv::absdiff(goldMean, actualMean.reshape(0,1), meanDiff);
cv::Scalar sDiff = cv::sum(meanDiff);
ASSERT_EQ(sDiff.dot(sDiff), 0.0);
}
/* End of file. */

View File

@@ -630,7 +630,7 @@ bool CV_OperationsTest::TestTemplateMat()
Mat_<uchar> matFromData(1, 4, uchar_data);
const Mat_<uchar> mat2 = matFromData.clone();
CHECK_DIFF(matFromData, eye.reshape(1));
CHECK_DIFF(matFromData, eye.reshape(1, 1));
if (matFromData(Point(0,0)) != uchar_data[0])throw test_excep();
if (mat2(Point(0,0)) != uchar_data[0]) throw test_excep();

View File

@@ -109,6 +109,10 @@ void Core_RandTest::run( int )
int dist_type = cvtest::randInt(rng) % (CV_RAND_NORMAL+1);
int i, k, SZ = N/cn;
Scalar A, B;
double eps = 1.e-4;
if (depth == CV_64F)
eps = 1.e-7;
bool do_sphere_test = dist_type == CV_RAND_UNI;
Mat arr[2], hist[4];
@@ -170,7 +174,7 @@ void Core_RandTest::run( int )
}
}
if( maxk >= 1 && norm(arr[0], arr[1], NORM_INF) != 0 )
if( maxk >= 1 && norm(arr[0], arr[1], NORM_INF) > eps)
{
ts->printf( cvtest::TS::LOG, "RNG output depends on the array lengths (some generated numbers get lost?)" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );