2010-05-18 17:41:28 +02:00
/*! \file core.hpp
\ brief The Core Functionality
*/
2010-05-11 19:44:00 +02:00
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
2011-04-17 15:14:45 +02:00
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
2010-05-11 19:44:00 +02:00
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
# ifndef __OPENCV_CORE_HPP__
# define __OPENCV_CORE_HPP__
2013-03-14 11:49:15 +01:00
# include "opencv2/core/cvdef.h"
2013-03-20 10:00:04 +01:00
# include "opencv2/core/version.hpp"
2013-03-14 11:49:15 +01:00
2010-05-11 19:44:00 +02:00
# ifdef __cplusplus
2013-03-27 12:54:04 +01:00
# include "opencv2/core/base.hpp"
2013-03-27 15:43:06 +01:00
# include "opencv2/core/cvstd.hpp"
2013-03-27 12:54:04 +01:00
# include "opencv2/core/traits.hpp"
# include "opencv2/core/matx.hpp"
2013-03-26 16:48:50 +01:00
# include "opencv2/core/types.hpp"
2013-03-27 15:43:06 +01:00
# endif
# include "opencv2/core/types_c.h"
# ifdef __cplusplus
2010-05-11 19:44:00 +02:00
# ifndef SKIP_INCLUDES
# include <limits.h>
# include <algorithm>
# include <cmath>
2011-04-07 00:00:09 +02:00
# include <cstddef>
2010-05-11 19:44:00 +02:00
# include <complex>
# include <map>
# include <new>
# include <vector>
2012-02-06 09:38:03 +01:00
# include <sstream>
2010-05-11 19:44:00 +02:00
# endif // SKIP_INCLUDES
2010-05-18 17:41:28 +02:00
/*! \namespace cv
Namespace where all the C + + OpenCV functionality resides
2012-05-28 13:22:43 +02:00
*/
2010-05-11 19:44:00 +02:00
namespace cv {
2010-09-21 17:15:44 +02:00
class CV_EXPORTS MatExpr ;
class CV_EXPORTS MatOp_Base ;
2010-10-12 14:31:40 +02:00
class CV_EXPORTS MatArg ;
class CV_EXPORTS MatConstIterator ;
2010-06-29 16:52:43 +02:00
template < typename _Tp > class CV_EXPORTS MatCommaInitializer_ ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
/*!
The standard OpenCV exception class .
Instances of the class are thrown by various functions and methods in the case of critical errors .
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS Exception : public std : : exception
{
public :
2011-04-17 15:14:45 +02:00
/*!
2010-05-18 17:41:28 +02:00
Default constructor
*/
2011-06-08 23:35:19 +02:00
Exception ( ) ;
2010-05-18 17:41:28 +02:00
/*!
Full constructor . Normally the constuctor is not called explicitly .
Instead , the macros CV_Error ( ) , CV_Error_ ( ) and CV_Assert ( ) are used .
*/
2013-03-22 17:37:49 +01:00
Exception ( int _code , const String & _err , const String & _func , const String & _file , int _line ) ;
2011-06-08 23:35:19 +02:00
virtual ~ Exception ( ) throw ( ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
/*!
\ return the error description and the context as a text string .
2012-05-28 13:22:43 +02:00
*/
2011-06-08 23:35:19 +02:00
virtual const char * what ( ) const throw ( ) ;
void formatMessage ( ) ;
2012-05-28 13:22:43 +02:00
2013-03-22 17:37:49 +01:00
String msg ; ///< the formatted error message
2010-05-11 19:44:00 +02:00
2011-04-17 15:14:45 +02:00
int code ; ///< error code @see CVStatus
2013-03-22 17:37:49 +01:00
String err ; ///< error description
String func ; ///< function name. Available only when the compiler supports __func__ macro
String file ; ///< source file name where the error has occured
2012-05-28 13:22:43 +02:00
int line ; ///< line number in the source file where the error has occured
2010-05-11 19:44:00 +02:00
} ;
2010-05-18 17:41:28 +02:00
2010-05-21 22:37:05 +02:00
//! Signals an error and raises the exception.
2012-05-28 13:22:43 +02:00
2010-05-21 22:37:05 +02:00
/*!
2010-05-18 17:41:28 +02:00
By default the function prints information about the error to stderr ,
then it either stops if setBreakOnError ( ) had been called before or raises the exception .
It is possible to alternate error processing by using redirectError ( ) .
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ param exc the exception raisen .
*/
2010-05-11 19:44:00 +02:00
CV_EXPORTS void error ( const Exception & exc ) ;
2010-05-18 17:41:28 +02:00
/*!
2010-05-21 22:37:05 +02:00
Allocates memory buffer
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
This is specialized OpenCV memory allocation function that returns properly aligned memory buffers .
The usage is identical to malloc ( ) . The allocated buffers must be freed with cv : : fastFree ( ) .
If there is not enough memory , the function calls cv : : error ( ) , which raises an exception .
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ param bufSize buffer size in bytes
\ return the allocated memory buffer .
2012-05-28 13:22:43 +02:00
*/
2010-05-18 17:41:28 +02:00
CV_EXPORTS void * fastMalloc ( size_t bufSize ) ;
/*!
2010-05-21 22:37:05 +02:00
Frees the memory allocated with cv : : fastMalloc
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
This is the corresponding deallocation function for cv : : fastMalloc ( ) .
When ptr = = NULL , the function has no effect .
*/
2010-05-11 19:44:00 +02:00
CV_EXPORTS void fastFree ( void * ptr ) ;
template < typename _Tp > static inline _Tp * allocate ( size_t n )
{
return new _Tp [ n ] ;
}
template < typename _Tp > static inline void deallocate ( _Tp * ptr , size_t )
{
delete [ ] ptr ;
}
2010-05-18 17:41:28 +02:00
/*!
The STL - compilant memory Allocator based on cv : : fastMalloc ( ) and cv : : fastFree ( )
*/
2010-05-11 19:44:00 +02:00
template < typename _Tp > class CV_EXPORTS Allocator
{
2012-05-28 13:22:43 +02:00
public :
2010-05-11 19:44:00 +02:00
typedef _Tp value_type ;
typedef value_type * pointer ;
typedef const value_type * const_pointer ;
typedef value_type & reference ;
typedef const value_type & const_reference ;
typedef size_t size_type ;
typedef ptrdiff_t difference_type ;
template < typename U > class rebind { typedef Allocator < U > other ; } ;
explicit Allocator ( ) { }
~ Allocator ( ) { }
explicit Allocator ( Allocator const & ) { }
template < typename U >
explicit Allocator ( Allocator < U > const & ) { }
// address
pointer address ( reference r ) { return & r ; }
const_pointer address ( const_reference r ) { return & r ; }
pointer allocate ( size_type count , const void * = 0 )
{ return reinterpret_cast < pointer > ( fastMalloc ( count * sizeof ( _Tp ) ) ) ; }
void deallocate ( pointer p , size_type ) { fastFree ( p ) ; }
size_type max_size ( ) const
{ return max ( static_cast < _Tp > ( - 1 ) / sizeof ( _Tp ) , 1 ) ; }
void construct ( pointer p , const _Tp & v ) { new ( static_cast < void * > ( p ) ) _Tp ( v ) ; }
void destroy ( pointer p ) { p - > ~ _Tp ( ) ; }
} ;
2010-11-06 22:51:21 +01:00
CV_EXPORTS void scalarToRawData ( const Scalar & s , void * buf , int type , int unroll_to = 0 ) ;
2013-03-26 11:58:09 +01:00
2010-11-18 11:54:12 +01:00
//////////////////// generic_type ref-counting pointer class for C/C++ objects ////////////////////////
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
/*!
Smart pointer to dynamically allocated objects .
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
This is template pointer - wrapping class that stores the associated reference counter along with the
object pointer . The class is similar to std : : smart_ptr < > from the recent addons to the C + + standard ,
but is shorter to write : ) and self - contained ( i . e . does add any dependency on the compiler or an external library ) .
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
Basically , you can use " Ptr<MyObjectType> ptr " ( or faster " const Ptr<MyObjectType>& ptr " for read - only access )
everywhere instead of " MyObjectType* ptr " , where MyObjectType is some C structure or a C + + class .
To make it all work , you need to specialize Ptr < > : : delete_obj ( ) , like :
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ code
template < > void Ptr < MyObjectType > : : delete_obj ( ) { call_destructor_func ( obj ) ; }
\ endcode
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ note { if MyObjectType is a C + + class with a destructor , you do not need to specialize delete_obj ( ) ,
since the default implementation calls " delete obj; " }
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ note { Another good property of the class is that the operations on the reference counter are atomic ,
i . e . it is safe to use the class in multi - threaded applications }
*/
2010-05-11 19:44:00 +02:00
template < typename _Tp > class CV_EXPORTS Ptr
{
public :
2010-05-18 17:41:28 +02:00
//! empty constructor
2010-05-11 19:44:00 +02:00
Ptr ( ) ;
2010-05-18 17:41:28 +02:00
//! take ownership of the pointer. The associated reference counter is allocated and set to 1
2010-05-11 19:44:00 +02:00
Ptr ( _Tp * _obj ) ;
2010-05-18 17:41:28 +02:00
//! calls release()
2010-05-11 19:44:00 +02:00
~ Ptr ( ) ;
2010-05-18 17:41:28 +02:00
//! copy constructor. Copies the members and calls addref()
2010-05-11 19:44:00 +02:00
Ptr ( const Ptr & ptr ) ;
2012-06-29 18:38:03 +02:00
template < typename _Tp2 > Ptr ( const Ptr < _Tp2 > & ptr ) ;
2010-05-18 17:41:28 +02:00
//! copy operator. Calls ptr.addref() and release() before copying the members
2010-05-11 19:44:00 +02:00
Ptr & operator = ( const Ptr & ptr ) ;
2010-05-18 17:41:28 +02:00
//! increments the reference counter
2010-05-11 19:44:00 +02:00
void addref ( ) ;
2010-05-18 17:41:28 +02:00
//! decrements the reference counter. If it reaches 0, delete_obj() is called
2010-05-11 19:44:00 +02:00
void release ( ) ;
2010-05-18 17:41:28 +02:00
//! deletes the object. Override if needed
2010-05-11 19:44:00 +02:00
void delete_obj ( ) ;
2010-05-18 17:41:28 +02:00
//! returns true iff obj==NULL
2010-05-11 19:44:00 +02:00
bool empty ( ) const ;
2012-01-24 21:14:07 +01:00
//! cast pointer to another type
template < typename _Tp2 > Ptr < _Tp2 > ptr ( ) ;
template < typename _Tp2 > const Ptr < _Tp2 > ptr ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! helper operators making "Ptr<T> ptr" use very similar to "T* ptr".
2010-05-11 19:44:00 +02:00
_Tp * operator - > ( ) ;
const _Tp * operator - > ( ) const ;
operator _Tp * ( ) ;
operator const _Tp * ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
_Tp * obj ; //< the object pointer.
2011-04-17 15:14:45 +02:00
int * refcount ; //< the associated reference counter
} ;
2012-12-21 20:27:29 +01:00
template < class T , class U > bool operator = = ( Ptr < T > const & a , Ptr < U > const & b ) ;
template < class T , class U > bool operator ! = ( Ptr < T > const & a , Ptr < U > const & b ) ;
2012-05-28 13:22:43 +02:00
2011-04-17 15:14:45 +02:00
//////////////////////// Input/Output Array Arguments /////////////////////////////////
2012-05-28 13:22:43 +02:00
2011-04-17 15:14:45 +02:00
/*!
2012-05-28 13:22:43 +02:00
Proxy datatype for passing Mat ' s and vector < > ' s as input parameters
2011-04-17 15:14:45 +02:00
*/
2011-06-06 16:51:27 +02:00
class CV_EXPORTS _InputArray
2011-04-17 15:14:45 +02:00
{
public :
2012-05-28 13:22:43 +02:00
enum {
2012-03-26 10:18:53 +02:00
KIND_SHIFT = 16 ,
FIXED_TYPE = 0x8000 < < KIND_SHIFT ,
FIXED_SIZE = 0x4000 < < KIND_SHIFT ,
KIND_MASK = ~ ( FIXED_TYPE | FIXED_SIZE ) - ( 1 < < KIND_SHIFT ) + 1 ,
2012-05-28 13:22:43 +02:00
NONE = 0 < < KIND_SHIFT ,
2011-11-30 07:20:29 +01:00
MAT = 1 < < KIND_SHIFT ,
2012-05-28 13:22:43 +02:00
MATX = 2 < < KIND_SHIFT ,
2011-11-30 07:20:29 +01:00
STD_VECTOR = 3 < < KIND_SHIFT ,
STD_VECTOR_VECTOR = 4 < < KIND_SHIFT ,
2012-05-28 13:22:43 +02:00
STD_VECTOR_MAT = 5 < < KIND_SHIFT ,
EXPR = 6 < < KIND_SHIFT ,
OPENGL_BUFFER = 7 < < KIND_SHIFT ,
2013-03-06 12:18:44 +01:00
OPENGL_TEXTURE = 8 < < KIND_SHIFT ,
2011-11-30 07:20:29 +01:00
GPU_MAT = 9 < < KIND_SHIFT
} ;
2011-06-06 16:51:27 +02:00
_InputArray ( ) ;
2012-06-07 19:21:29 +02:00
2011-06-06 16:51:27 +02:00
_InputArray ( const Mat & m ) ;
_InputArray ( const MatExpr & expr ) ;
2011-11-08 13:01:49 +01:00
template < typename _Tp > _InputArray ( const _Tp * vec , int n ) ;
2013-02-24 17:14:01 +01:00
template < typename _Tp > _InputArray ( const std : : vector < _Tp > & vec ) ;
template < typename _Tp > _InputArray ( const std : : vector < std : : vector < _Tp > > & vec ) ;
_InputArray ( const std : : vector < Mat > & vec ) ;
template < typename _Tp > _InputArray ( const std : : vector < Mat_ < _Tp > > & vec ) ;
2012-03-26 10:18:53 +02:00
template < typename _Tp > _InputArray ( const Mat_ < _Tp > & m ) ;
2011-06-06 16:51:27 +02:00
template < typename _Tp , int m , int n > _InputArray ( const Matx < _Tp , m , n > & matx ) ;
2011-08-06 20:52:05 +02:00
_InputArray ( const Scalar & s ) ;
2011-06-06 16:51:27 +02:00
_InputArray ( const double & val ) ;
2011-11-30 07:20:29 +01:00
_InputArray ( const gpu : : GpuMat & d_mat ) ;
2013-03-06 12:18:44 +01:00
_InputArray ( const ogl : : Buffer & buf ) ;
_InputArray ( const ogl : : Texture2D & tex ) ;
2011-11-30 07:20:29 +01:00
2011-06-06 16:51:27 +02:00
virtual Mat getMat ( int i = - 1 ) const ;
2013-02-24 17:14:01 +01:00
virtual void getMatVector ( std : : vector < Mat > & mv ) const ;
2011-11-30 07:20:29 +01:00
virtual gpu : : GpuMat getGpuMat ( ) const ;
2013-03-06 12:18:44 +01:00
virtual ogl : : Buffer getOGlBuffer ( ) const ;
virtual ogl : : Texture2D getOGlTexture2D ( ) const ;
2011-11-30 07:20:29 +01:00
2011-06-06 16:51:27 +02:00
virtual int kind ( ) const ;
virtual Size size ( int i = - 1 ) const ;
virtual size_t total ( int i = - 1 ) const ;
virtual int type ( int i = - 1 ) const ;
virtual int depth ( int i = - 1 ) const ;
virtual int channels ( int i = - 1 ) const ;
virtual bool empty ( ) const ;
2011-04-17 15:14:45 +02:00
2012-12-22 18:14:14 +01:00
virtual ~ _InputArray ( ) ;
2012-06-07 19:21:29 +02:00
2011-04-17 15:14:45 +02:00
int flags ;
void * obj ;
Size sz ;
} ;
enum
{
DEPTH_MASK_8U = 1 < < CV_8U ,
DEPTH_MASK_8S = 1 < < CV_8S ,
DEPTH_MASK_16U = 1 < < CV_16U ,
DEPTH_MASK_16S = 1 < < CV_16S ,
DEPTH_MASK_32S = 1 < < CV_32S ,
DEPTH_MASK_32F = 1 < < CV_32F ,
DEPTH_MASK_64F = 1 < < CV_64F ,
DEPTH_MASK_ALL = ( DEPTH_MASK_64F < < 1 ) - 1 ,
DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~ DEPTH_MASK_8S ,
DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
} ;
/*!
2012-05-28 13:22:43 +02:00
Proxy datatype for passing Mat ' s and vector < > ' s as input parameters
2011-04-17 15:14:45 +02:00
*/
2011-06-06 16:51:27 +02:00
class CV_EXPORTS _OutputArray : public _InputArray
2011-04-17 15:14:45 +02:00
{
public :
2011-06-06 16:51:27 +02:00
_OutputArray ( ) ;
2012-03-26 10:18:53 +02:00
2011-06-06 16:51:27 +02:00
_OutputArray ( Mat & m ) ;
2013-02-24 17:14:01 +01:00
template < typename _Tp > _OutputArray ( std : : vector < _Tp > & vec ) ;
template < typename _Tp > _OutputArray ( std : : vector < std : : vector < _Tp > > & vec ) ;
_OutputArray ( std : : vector < Mat > & vec ) ;
template < typename _Tp > _OutputArray ( std : : vector < Mat_ < _Tp > > & vec ) ;
2012-03-26 10:18:53 +02:00
template < typename _Tp > _OutputArray ( Mat_ < _Tp > & m ) ;
2011-06-06 16:51:27 +02:00
template < typename _Tp , int m , int n > _OutputArray ( Matx < _Tp , m , n > & matx ) ;
2011-11-08 13:01:49 +01:00
template < typename _Tp > _OutputArray ( _Tp * vec , int n ) ;
2012-10-02 12:34:17 +02:00
_OutputArray ( gpu : : GpuMat & d_mat ) ;
2013-03-06 12:18:44 +01:00
_OutputArray ( ogl : : Buffer & buf ) ;
_OutputArray ( ogl : : Texture2D & tex ) ;
2012-03-26 10:18:53 +02:00
_OutputArray ( const Mat & m ) ;
2013-02-24 17:14:01 +01:00
template < typename _Tp > _OutputArray ( const std : : vector < _Tp > & vec ) ;
template < typename _Tp > _OutputArray ( const std : : vector < std : : vector < _Tp > > & vec ) ;
_OutputArray ( const std : : vector < Mat > & vec ) ;
template < typename _Tp > _OutputArray ( const std : : vector < Mat_ < _Tp > > & vec ) ;
2012-03-26 10:18:53 +02:00
template < typename _Tp > _OutputArray ( const Mat_ < _Tp > & m ) ;
template < typename _Tp , int m , int n > _OutputArray ( const Matx < _Tp , m , n > & matx ) ;
template < typename _Tp > _OutputArray ( const _Tp * vec , int n ) ;
2012-10-02 12:34:17 +02:00
_OutputArray ( const gpu : : GpuMat & d_mat ) ;
2013-03-06 12:18:44 +01:00
_OutputArray ( const ogl : : Buffer & buf ) ;
_OutputArray ( const ogl : : Texture2D & tex ) ;
2012-03-26 10:18:53 +02:00
2011-06-06 16:51:27 +02:00
virtual bool fixedSize ( ) const ;
virtual bool fixedType ( ) const ;
virtual bool needed ( ) const ;
virtual Mat & getMatRef ( int i = - 1 ) const ;
2012-10-16 17:35:28 +02:00
virtual gpu : : GpuMat & getGpuMatRef ( ) const ;
2013-03-06 12:18:44 +01:00
virtual ogl : : Buffer & getOGlBufferRef ( ) const ;
virtual ogl : : Texture2D & getOGlTexture2DRef ( ) const ;
2012-03-26 10:18:53 +02:00
virtual void create ( Size sz , int type , int i = - 1 , bool allowTransposed = false , int fixedDepthMask = 0 ) const ;
2011-06-06 16:51:27 +02:00
virtual void create ( int rows , int cols , int type , int i = - 1 , bool allowTransposed = false , int fixedDepthMask = 0 ) const ;
virtual void create ( int dims , const int * size , int type , int i = - 1 , bool allowTransposed = false , int fixedDepthMask = 0 ) const ;
virtual void release ( ) const ;
virtual void clear ( ) const ;
2012-06-07 19:21:29 +02:00
2012-12-22 18:14:14 +01:00
virtual ~ _OutputArray ( ) ;
2010-05-11 19:44:00 +02:00
} ;
2011-06-06 16:51:27 +02:00
typedef const _InputArray & InputArray ;
2011-04-17 15:14:45 +02:00
typedef InputArray InputArrayOfArrays ;
2011-06-06 16:51:27 +02:00
typedef const _OutputArray & OutputArray ;
2011-04-17 15:14:45 +02:00
typedef OutputArray OutputArrayOfArrays ;
2011-06-06 16:51:27 +02:00
typedef OutputArray InputOutputArray ;
2011-07-18 18:31:30 +02:00
typedef OutputArray InputOutputArrayOfArrays ;
2011-06-06 16:51:27 +02:00
2011-06-08 08:55:04 +02:00
CV_EXPORTS OutputArray noArray ( ) ;
2011-04-17 15:14:45 +02:00
/////////////////////////////////////// Mat ///////////////////////////////////////////
2010-05-11 19:44:00 +02:00
enum { MAGIC_MASK = 0xFFFF0000 , TYPE_MASK = 0x00000FFF , DEPTH_MASK = 7 } ;
2010-05-18 17:41:28 +02:00
/*!
2010-10-12 14:31:40 +02:00
Custom array allocator
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
*/
2010-10-19 13:57:37 +02:00
class CV_EXPORTS MatAllocator
2010-10-12 14:31:40 +02:00
{
public :
2010-10-19 13:57:37 +02:00
MatAllocator ( ) { }
virtual ~ MatAllocator ( ) { }
2010-10-12 14:31:40 +02:00
virtual void allocate ( int dims , const int * sizes , int type , int * & refcount ,
uchar * & datastart , uchar * & data , size_t * step ) = 0 ;
virtual void deallocate ( int * refcount , uchar * datastart , uchar * data ) = 0 ;
} ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
/*!
The n - dimensional matrix class .
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
The class represents an n - dimensional dense numerical array that can act as
a matrix , image , optical flow map , 3 - focal tensor etc .
It is very similar to CvMat and CvMatND types from earlier versions of OpenCV ,
and similarly to those types , the matrix can be multi - channel . It also fully supports ROI mechanism .
2010-05-18 17:41:28 +02:00
There are many different ways to create cv : : Mat object . Here are the some popular ones :
< ul >
< li > using cv : : Mat : : create ( nrows , ncols , type ) method or
the similar constructor cv : : Mat : : Mat ( nrows , ncols , type [ , fill_value ] ) constructor .
A new matrix of the specified size and specifed type will be allocated .
" type " has the same meaning as in cvCreateMat function ,
e . g . CV_8UC1 means 8 - bit single - channel matrix , CV_32FC2 means 2 - channel ( i . e . complex )
floating - point matrix etc :
\ code
// make 7x7 complex matrix filled with 1+3j.
cv : : Mat M ( 7 , 7 , CV_32FC2 , Scalar ( 1 , 3 ) ) ;
// and now turn M to 100x60 15-channel 8-bit matrix.
// The old content will be deallocated
M . create ( 100 , 60 , CV_8UC ( 15 ) ) ;
\ endcode
2010-05-25 17:59:48 +02:00
As noted in the introduction of this chapter , Mat : : create ( )
2010-05-18 17:41:28 +02:00
will only allocate a new matrix when the current matrix dimensionality
or type are different from the specified .
< li > by using a copy constructor or assignment operator , where on the right side it can
be a matrix or expression , see below . Again , as noted in the introduction ,
matrix assignment is O ( 1 ) operation because it only copies the header
and increases the reference counter . cv : : Mat : : clone ( ) method can be used to get a full
( a . k . a . deep ) copy of the matrix when you need it .
< li > by constructing a header for a part of another matrix . It can be a single row , single column ,
several rows , several columns , rectangular region in the matrix ( called a minor in algebra ) or
a diagonal . Such operations are also O ( 1 ) , because the new header will reference the same data .
You can actually modify a part of the matrix using this feature , e . g .
\ code
// add 5-th row, multiplied by 3 to the 3rd row
M . row ( 3 ) = M . row ( 3 ) + M . row ( 5 ) * 3 ;
// now copy 7-th column to the 1-st column
// M.col(1) = M.col(7); // this will not work
Mat M1 = M . col ( 1 ) ;
M . col ( 7 ) . copyTo ( M1 ) ;
// create new 320x240 image
cv : : Mat img ( Size ( 320 , 240 ) , CV_8UC3 ) ;
// select a roi
cv : : Mat roi ( img , Rect ( 10 , 10 , 100 , 100 ) ) ;
// fill the ROI with (0,255,0) (which is green in RGB space);
// the original 320x240 image will be modified
roi = Scalar ( 0 , 255 , 0 ) ;
\ endcode
Thanks to the additional cv : : Mat : : datastart and cv : : Mat : : dataend members , it is possible to
compute the relative sub - matrix position in the main " container " matrix using cv : : Mat : : locateROI ( ) :
\ code
Mat A = Mat : : eye ( 10 , 10 , CV_32S ) ;
// extracts A columns, 1 (inclusive) to 3 (exclusive).
Mat B = A ( Range : : all ( ) , Range ( 1 , 3 ) ) ;
// extracts B rows, 5 (inclusive) to 9 (exclusive).
// that is, C ~ A(Range(5, 9), Range(1, 3))
Mat C = B ( Range ( 5 , 9 ) , Range : : all ( ) ) ;
Size size ; Point ofs ;
C . locateROI ( size , ofs ) ;
// size will be (width=10,height=10) and the ofs will be (x=1, y=5)
\ endcode
As in the case of whole matrices , if you need a deep copy , use cv : : Mat : : clone ( ) method
of the extracted sub - matrices .
< li > by making a header for user - allocated - data . It can be useful for
< ol >
< li > processing " foreign " data using OpenCV ( e . g . when you implement
a DirectShow filter or a processing module for gstreamer etc . ) , e . g .
\ code
void process_video_frame ( const unsigned char * pixels ,
int width , int height , int step )
{
cv : : Mat img ( height , width , CV_8UC3 , pixels , step ) ;
cv : : GaussianBlur ( img , img , cv : : Size ( 7 , 7 ) , 1.5 , 1.5 ) ;
}
\ endcode
< li > for quick initialization of small matrices and / or super - fast element access
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ code
double m [ 3 ] [ 3 ] = { { a , b , c } , { d , e , f } , { g , h , i } } ;
cv : : Mat M = cv : : Mat ( 3 , 3 , CV_64F , m ) . inv ( ) ;
\ endcode
2012-05-28 13:22:43 +02:00
< / ol >
2010-05-18 17:41:28 +02:00
partial yet very common cases of this " user-allocated data " case are conversions
from CvMat and IplImage to cv : : Mat . For this purpose there are special constructors
taking pointers to CvMat or IplImage and the optional
flag indicating whether to copy the data or not .
Backward conversion from cv : : Mat to CvMat or IplImage is provided via cast operators
cv : : Mat : : operator CvMat ( ) an cv : : Mat : : operator IplImage ( ) .
The operators do not copy the data .
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ code
IplImage * img = cvLoadImage ( " greatwave.jpg " , 1 ) ;
Mat mtx ( img ) ; // convert IplImage* -> cv::Mat
CvMat oldmat = mtx ; // convert cv::Mat -> CvMat
CV_Assert ( oldmat . cols = = img - > width & & oldmat . rows = = img - > height & &
oldmat . data . ptr = = ( uchar * ) img - > imageData & & oldmat . step = = img - > widthStep ) ;
\ endcode
< li > by using MATLAB - style matrix initializers , cv : : Mat : : zeros ( ) , cv : : Mat : : ones ( ) , cv : : Mat : : eye ( ) , e . g . :
\ code
// create a double-precision identity martix and add it to M.
M + = Mat : : eye ( M . rows , M . cols , CV_64F ) ;
\ endcode
< li > by using comma - separated initializer :
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ code
// create 3x3 double-precision identity matrix
Mat M = ( Mat_ < double > ( 3 , 3 ) < < 1 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 ) ;
\ endcode
here we first call constructor of cv : : Mat_ class ( that we describe further ) with the proper matrix ,
and then we just put " << " operator followed by comma - separated values that can be constants ,
variables , expressions etc . Also , note the extra parentheses that are needed to avoid compiler errors .
< / ul >
Once matrix is created , it will be automatically managed by using reference - counting mechanism
( unless the matrix header is built on top of user - allocated data ,
in which case you should handle the data by yourself ) .
The matrix data will be deallocated when no one points to it ;
if you want to release the data pointed by a matrix header before the matrix destructor is called ,
use cv : : Mat : : release ( ) .
The next important thing to learn about the matrix class is element access . Here is how the matrix is stored .
The elements are stored in row - major order ( row by row ) . The cv : : Mat : : data member points to the first element of the first row ,
cv : : Mat : : rows contains the number of matrix rows and cv : : Mat : : cols - the number of matrix columns . There is yet another member ,
cv : : Mat : : step that is used to actually compute address of a matrix element . cv : : Mat : : step is needed because the matrix can be
a part of another matrix or because there can some padding space in the end of each row for a proper alignment .
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
\ image html roi . png
Given these parameters , address of the matrix element M_ { ij } is computed as following :
addr ( M_ { ij } ) = M . data + M . step * i + j * M . elemSize ( )
if you know the matrix element type , e . g . it is float , then you can use cv : : Mat : : at ( ) method :
addr ( M_ { ij } ) = & M . at < float > ( i , j )
( where & is used to convert the reference returned by cv : : Mat : : at ( ) to a pointer ) .
2010-05-25 17:59:48 +02:00
if you need to process a whole row of matrix , the most efficient way is to get
the pointer to the row first , and then just use plain C operator [ ] :
2010-05-18 17:41:28 +02:00
\ code
// compute sum of positive matrix elements
// (assuming that M is double-precision matrix)
double sum = 0 ;
for ( int i = 0 ; i < M . rows ; i + + )
{
const double * Mi = M . ptr < double > ( i ) ;
for ( int j = 0 ; j < M . cols ; j + + )
sum + = std : : max ( Mi [ j ] , 0. ) ;
}
\ endcode
Some operations , like the above one , do not actually depend on the matrix shape ,
they just process elements of a matrix one by one ( or elements from multiple matrices
that are sitting in the same place , e . g . matrix addition ) . Such operations are called
element - wise and it makes sense to check whether all the input / output matrices are continuous ,
i . e . have no gaps in the end of each row , and if yes , process them as a single long row :
\ code
// compute sum of positive matrix elements, optimized variant
double sum = 0 ;
int cols = M . cols , rows = M . rows ;
if ( M . isContinuous ( ) )
{
cols * = rows ;
rows = 1 ;
}
for ( int i = 0 ; i < rows ; i + + )
{
const double * Mi = M . ptr < double > ( i ) ;
for ( int j = 0 ; j < cols ; j + + )
sum + = std : : max ( Mi [ j ] , 0. ) ;
}
\ endcode
in the case of continuous matrix the outer loop body will be executed just once ,
so the overhead will be smaller , which will be especially noticeable in the case of small matrices .
Finally , there are STL - style iterators that are smart enough to skip gaps between successive rows :
\ code
// compute sum of positive matrix elements, iterator-based variant
double sum = 0 ;
MatConstIterator_ < double > it = M . begin < double > ( ) , it_end = M . end < double > ( ) ;
for ( ; it ! = it_end ; + + it )
sum + = std : : max ( * it , 0. ) ;
\ endcode
2010-05-25 17:59:48 +02:00
The matrix iterators are random - access iterators , so they can be passed
to any STL algorithm , including std : : sort ( ) .
2010-05-18 17:41:28 +02:00
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS Mat
{
public :
2010-05-18 17:41:28 +02:00
//! default constructor
2010-05-11 19:44:00 +02:00
Mat ( ) ;
2010-10-12 14:31:40 +02:00
//! constructs 2D matrix of the specified size and type
2010-05-11 19:44:00 +02:00
// (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
2012-05-28 13:22:43 +02:00
Mat ( int rows , int cols , int type ) ;
Mat ( Size size , int type ) ;
2010-10-12 14:31:40 +02:00
//! constucts 2D matrix and fills it with the specified value _s.
2012-05-28 13:22:43 +02:00
Mat ( int rows , int cols , int type , const Scalar & s ) ;
Mat ( Size size , int type , const Scalar & s ) ;
2010-10-12 14:31:40 +02:00
//! constructs n-dimensional matrix
2012-05-28 13:22:43 +02:00
Mat ( int ndims , const int * sizes , int type ) ;
Mat ( int ndims , const int * sizes , int type , const Scalar & s ) ;
2010-05-18 17:41:28 +02:00
//! copy constructor
2010-05-11 19:44:00 +02:00
Mat ( const Mat & m ) ;
2010-05-18 17:41:28 +02:00
//! constructor for matrix headers pointing to user-allocated data
2012-05-28 13:22:43 +02:00
Mat ( int rows , int cols , int type , void * data , size_t step = AUTO_STEP ) ;
Mat ( Size size , int type , void * data , size_t step = AUTO_STEP ) ;
Mat ( int ndims , const int * sizes , int type , void * data , const size_t * steps = 0 ) ;
2010-05-18 17:41:28 +02:00
//! creates a matrix header for a part of the bigger matrix
2010-10-12 14:31:40 +02:00
Mat ( const Mat & m , const Range & rowRange , const Range & colRange = Range : : all ( ) ) ;
2010-05-11 19:44:00 +02:00
Mat ( const Mat & m , const Rect & roi ) ;
2010-10-12 14:31:40 +02:00
Mat ( const Mat & m , const Range * ranges ) ;
2010-05-18 17:41:28 +02:00
//! converts old-style CvMat to the new matrix; the data is not copied by default
2010-05-11 19:44:00 +02:00
Mat ( const CvMat * m , bool copyData = false ) ;
2010-10-12 14:31:40 +02:00
//! converts old-style CvMatND to the new matrix; the data is not copied by default
Mat ( const CvMatND * m , bool copyData = false ) ;
2010-05-18 17:41:28 +02:00
//! converts old-style IplImage to the new matrix; the data is not copied by default
2010-05-11 19:44:00 +02:00
Mat ( const IplImage * img , bool copyData = false ) ;
2010-05-18 17:41:28 +02:00
//! builds matrix from std::vector with or without copying the data
2013-02-24 17:14:01 +01:00
template < typename _Tp > explicit Mat ( const std : : vector < _Tp > & vec , bool copyData = false ) ;
2010-06-29 16:52:43 +02:00
//! builds matrix from cv::Vec; the data is copied by default
2012-05-28 13:22:43 +02:00
template < typename _Tp , int n > explicit Mat ( const Vec < _Tp , n > & vec , bool copyData = true ) ;
2010-06-29 16:52:43 +02:00
//! builds matrix from cv::Matx; the data is copied by default
2012-05-28 13:22:43 +02:00
template < typename _Tp , int m , int n > explicit Mat ( const Matx < _Tp , m , n > & mtx , bool copyData = true ) ;
2010-05-18 17:41:28 +02:00
//! builds matrix from a 2D point
2010-10-12 14:31:40 +02:00
template < typename _Tp > explicit Mat ( const Point_ < _Tp > & pt , bool copyData = true ) ;
2010-05-18 17:41:28 +02:00
//! builds matrix from a 3D point
2010-10-12 14:31:40 +02:00
template < typename _Tp > explicit Mat ( const Point3_ < _Tp > & pt , bool copyData = true ) ;
2010-06-09 20:17:50 +02:00
//! builds matrix from comma initializer
template < typename _Tp > explicit Mat ( const MatCommaInitializer_ < _Tp > & commaInitializer ) ;
2011-11-09 14:13:52 +01:00
//! download data from GpuMat
explicit Mat ( const gpu : : GpuMat & m ) ;
2010-05-18 17:41:28 +02:00
//! destructor - calls release()
2010-05-11 19:44:00 +02:00
~ Mat ( ) ;
2010-05-18 17:41:28 +02:00
//! assignment operators
2010-05-11 19:44:00 +02:00
Mat & operator = ( const Mat & m ) ;
2010-09-21 17:15:44 +02:00
Mat & operator = ( const MatExpr & expr ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! returns a new matrix header for the specified row
2010-05-11 19:44:00 +02:00
Mat row ( int y ) const ;
2010-05-18 17:41:28 +02:00
//! returns a new matrix header for the specified column
2010-05-11 19:44:00 +02:00
Mat col ( int x ) const ;
2010-05-18 17:41:28 +02:00
//! ... for the specified row span
2010-05-11 19:44:00 +02:00
Mat rowRange ( int startrow , int endrow ) const ;
Mat rowRange ( const Range & r ) const ;
2010-05-18 17:41:28 +02:00
//! ... for the specified column span
2010-05-11 19:44:00 +02:00
Mat colRange ( int startcol , int endcol ) const ;
Mat colRange ( const Range & r ) const ;
2010-05-18 17:41:28 +02:00
//! ... for the specified diagonal
2010-05-11 19:44:00 +02:00
// (d=0 - the main diagonal,
// >0 - a diagonal from the lower half,
// <0 - a diagonal from the upper half)
Mat diag ( int d = 0 ) const ;
2010-05-18 17:41:28 +02:00
//! constructs a square diagonal matrix which main diagonal is vector "d"
2010-05-11 19:44:00 +02:00
static Mat diag ( const Mat & d ) ;
2010-05-18 17:41:28 +02:00
//! returns deep copy of the matrix, i.e. the data is copied
2010-05-11 19:44:00 +02:00
Mat clone ( ) const ;
2010-05-18 17:41:28 +02:00
//! copies the matrix content to "m".
2010-05-11 19:44:00 +02:00
// It calls m.create(this->size(), this->type()).
2011-04-17 15:14:45 +02:00
void copyTo ( OutputArray m ) const ;
2010-05-18 17:41:28 +02:00
//! copies those matrix elements to "m" that are marked with non-zero mask elements.
2011-06-06 16:51:27 +02:00
void copyTo ( OutputArray m , InputArray mask ) const ;
2010-05-18 17:41:28 +02:00
//! converts matrix to another datatype with optional scalng. See cvConvertScale.
2011-04-17 15:14:45 +02:00
void convertTo ( OutputArray m , int rtype , double alpha = 1 , double beta = 0 ) const ;
2010-05-11 19:44:00 +02:00
void assignTo ( Mat & m , int type = - 1 ) const ;
2010-05-18 17:41:28 +02:00
//! sets every matrix element to s
2010-05-11 19:44:00 +02:00
Mat & operator = ( const Scalar & s ) ;
2010-05-18 17:41:28 +02:00
//! sets some of the matrix elements to s, according to the mask
2011-06-13 22:56:27 +02:00
Mat & setTo ( InputArray value , InputArray mask = noArray ( ) ) ;
2010-05-18 17:41:28 +02:00
//! creates alternative matrix header for the same data, with different
2010-05-11 19:44:00 +02:00
// number of channels and/or different number of rows. see cvReshape.
2012-05-28 13:22:43 +02:00
Mat reshape ( int cn , int rows = 0 ) const ;
Mat reshape ( int cn , int newndims , const int * newsz ) const ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! matrix transposition by means of matrix expressions
2010-09-21 17:15:44 +02:00
MatExpr t ( ) const ;
2010-05-18 17:41:28 +02:00
//! matrix inversion by means of matrix expressions
2010-09-21 17:15:44 +02:00
MatExpr inv ( int method = DECOMP_LU ) const ;
2010-05-18 17:41:28 +02:00
//! per-element matrix multiplication by means of matrix expressions
2011-06-06 16:51:27 +02:00
MatExpr mul ( InputArray m , double scale = 1 ) const ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! computes cross-product of 2 3D vectors
2011-06-06 16:51:27 +02:00
Mat cross ( InputArray m ) const ;
2010-05-18 17:41:28 +02:00
//! computes dot-product
2011-06-06 16:51:27 +02:00
double dot ( InputArray m ) const ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! Matlab-style matrix initialization
2010-09-21 17:15:44 +02:00
static MatExpr zeros ( int rows , int cols , int type ) ;
static MatExpr zeros ( Size size , int type ) ;
2010-10-12 14:31:40 +02:00
static MatExpr zeros ( int ndims , const int * sz , int type ) ;
2010-09-21 17:15:44 +02:00
static MatExpr ones ( int rows , int cols , int type ) ;
static MatExpr ones ( Size size , int type ) ;
2010-10-12 14:31:40 +02:00
static MatExpr ones ( int ndims , const int * sz , int type ) ;
2010-09-21 17:15:44 +02:00
static MatExpr eye ( int rows , int cols , int type ) ;
static MatExpr eye ( Size size , int type ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! allocates new matrix data unless the matrix already has specified size and type.
2010-05-11 19:44:00 +02:00
// previous data is unreferenced if needed.
2012-05-28 13:22:43 +02:00
void create ( int rows , int cols , int type ) ;
void create ( Size size , int type ) ;
void create ( int ndims , const int * sizes , int type ) ;
2010-05-18 17:41:28 +02:00
//! increases the reference counter; use with care to avoid memleaks
2010-05-11 19:44:00 +02:00
void addref ( ) ;
2010-05-18 17:41:28 +02:00
//! decreases reference counter;
2010-10-12 14:31:40 +02:00
// deallocates the data when reference counter reaches 0.
2010-05-11 19:44:00 +02:00
void release ( ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! deallocates the matrix data
void deallocate ( ) ;
//! internal use function; properly re-allocates _size, _step arrays
void copySize ( const Mat & m ) ;
2012-05-28 13:22:43 +02:00
2010-10-18 10:51:46 +02:00
//! reserves enough space to fit sz hyper-planes
void reserve ( size_t sz ) ;
//! resizes matrix to the specified number of hyper-planes
void resize ( size_t sz ) ;
//! resizes matrix to the specified number of hyper-planes; initializes the newly added elements
void resize ( size_t sz , const Scalar & s ) ;
//! internal function
void push_back_ ( const void * elem ) ;
//! adds element to the end of 1d matrix (or possibly multiple elements when _Tp=Mat)
template < typename _Tp > void push_back ( const _Tp & elem ) ;
template < typename _Tp > void push_back ( const Mat_ < _Tp > & elem ) ;
void push_back ( const Mat & m ) ;
//! removes several hyper-planes from bottom of the matrix
2010-11-23 17:39:20 +01:00
void pop_back ( size_t nelems = 1 ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! locates matrix header within a parent matrix. See below
2010-05-11 19:44:00 +02:00
void locateROI ( Size & wholeSize , Point & ofs ) const ;
2010-05-18 17:41:28 +02:00
//! moves/resizes the current matrix ROI inside the parent matrix.
2010-05-11 19:44:00 +02:00
Mat & adjustROI ( int dtop , int dbottom , int dleft , int dright ) ;
2010-05-18 17:41:28 +02:00
//! extracts a rectangular sub-matrix
2010-05-11 19:44:00 +02:00
// (this is a generalized form of row, rowRange etc.)
Mat operator ( ) ( Range rowRange , Range colRange ) const ;
Mat operator ( ) ( const Rect & roi ) const ;
2010-10-12 14:31:40 +02:00
Mat operator ( ) ( const Range * ranges ) const ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! converts header to CvMat; no data is copied
2010-05-11 19:44:00 +02:00
operator CvMat ( ) const ;
2010-10-12 14:31:40 +02:00
//! converts header to CvMatND; no data is copied
operator CvMatND ( ) const ;
2010-05-18 17:41:28 +02:00
//! converts header to IplImage; no data is copied
2010-05-11 19:44:00 +02:00
operator IplImage ( ) const ;
2012-05-28 13:22:43 +02:00
2013-02-24 17:14:01 +01:00
template < typename _Tp > operator std : : vector < _Tp > ( ) const ;
2010-07-29 08:51:19 +02:00
template < typename _Tp , int n > operator Vec < _Tp , n > ( ) const ;
template < typename _Tp , int m , int n > operator Matx < _Tp , m , n > ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! returns true iff the matrix data is continuous
2010-05-11 19:44:00 +02:00
// (i.e. when there are no gaps between successive rows).
// similar to CV_IS_MAT_CONT(cvmat->type)
bool isContinuous ( ) const ;
2012-05-28 13:22:43 +02:00
2010-10-18 10:51:46 +02:00
//! returns true if the matrix is a submatrix of another matrix
bool isSubmatrix ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! returns element size in bytes,
2010-05-11 19:44:00 +02:00
// similar to CV_ELEM_SIZE(cvmat->type)
size_t elemSize ( ) const ;
2010-05-18 17:41:28 +02:00
//! returns the size of element channel in bytes.
2010-05-11 19:44:00 +02:00
size_t elemSize1 ( ) const ;
2010-05-18 17:41:28 +02:00
//! returns element type, similar to CV_MAT_TYPE(cvmat->type)
2010-05-11 19:44:00 +02:00
int type ( ) const ;
2010-05-18 17:41:28 +02:00
//! returns element type, similar to CV_MAT_DEPTH(cvmat->type)
2010-05-11 19:44:00 +02:00
int depth ( ) const ;
2010-05-18 17:41:28 +02:00
//! returns element type, similar to CV_MAT_CN(cvmat->type)
2010-05-11 19:44:00 +02:00
int channels ( ) const ;
2010-05-18 17:41:28 +02:00
//! returns step/elemSize1()
2010-10-12 14:31:40 +02:00
size_t step1 ( int i = 0 ) const ;
2010-05-18 17:41:28 +02:00
//! returns true if matrix data is NULL
2010-05-11 19:44:00 +02:00
bool empty ( ) const ;
2010-10-12 14:31:40 +02:00
//! returns the total number of matrix elements
size_t total ( ) const ;
2012-05-28 13:22:43 +02:00
2010-10-27 20:26:39 +02:00
//! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise
int checkVector ( int elemChannels , int depth = - 1 , bool requireContinuous = true ) const ;
2010-05-11 19:44:00 +02:00
2010-10-12 14:31:40 +02:00
//! returns pointer to i0-th submatrix along the dimension #0
uchar * ptr ( int i0 = 0 ) ;
const uchar * ptr ( int i0 = 0 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! returns pointer to (i0,i1) submatrix along the dimensions #0 and #1
uchar * ptr ( int i0 , int i1 ) ;
const uchar * ptr ( int i0 , int i1 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! returns pointer to (i0,i1,i3) submatrix along the dimensions #0, #1, #2
uchar * ptr ( int i0 , int i1 , int i2 ) ;
const uchar * ptr ( int i0 , int i1 , int i2 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! returns pointer to the matrix element
uchar * ptr ( const int * idx ) ;
//! returns read-only pointer to the matrix element
const uchar * ptr ( const int * idx ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < int n > uchar * ptr ( const Vec < int , n > & idx ) ;
template < int n > const uchar * ptr ( const Vec < int , n > & idx ) const ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! template version of the above method
2010-10-12 14:31:40 +02:00
template < typename _Tp > _Tp * ptr ( int i0 = 0 ) ;
template < typename _Tp > const _Tp * ptr ( int i0 = 0 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < typename _Tp > _Tp * ptr ( int i0 , int i1 ) ;
template < typename _Tp > const _Tp * ptr ( int i0 , int i1 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < typename _Tp > _Tp * ptr ( int i0 , int i1 , int i2 ) ;
template < typename _Tp > const _Tp * ptr ( int i0 , int i1 , int i2 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < typename _Tp > _Tp * ptr ( const int * idx ) ;
template < typename _Tp > const _Tp * ptr ( const int * idx ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < typename _Tp , int n > _Tp * ptr ( const Vec < int , n > & idx ) ;
template < typename _Tp , int n > const _Tp * ptr ( const Vec < int , n > & idx ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! the same as above, with the pointer dereferencing
template < typename _Tp > _Tp & at ( int i0 = 0 ) ;
template < typename _Tp > const _Tp & at ( int i0 = 0 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < typename _Tp > _Tp & at ( int i0 , int i1 ) ;
template < typename _Tp > const _Tp & at ( int i0 , int i1 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < typename _Tp > _Tp & at ( int i0 , int i1 , int i2 ) ;
template < typename _Tp > const _Tp & at ( int i0 , int i1 , int i2 ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < typename _Tp > _Tp & at ( const int * idx ) ;
template < typename _Tp > const _Tp & at ( const int * idx ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
template < typename _Tp , int n > _Tp & at ( const Vec < int , n > & idx ) ;
template < typename _Tp , int n > const _Tp & at ( const Vec < int , n > & idx ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! special versions for 2D arrays (especially convenient for referencing image pixels)
2010-05-11 19:44:00 +02:00
template < typename _Tp > _Tp & at ( Point pt ) ;
template < typename _Tp > const _Tp & at ( Point pt ) const ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! template methods for iteration over matrix elements.
2010-05-11 19:44:00 +02:00
// the iterators take care of skipping gaps in the end of rows (if any)
template < typename _Tp > MatIterator_ < _Tp > begin ( ) ;
template < typename _Tp > MatIterator_ < _Tp > end ( ) ;
template < typename _Tp > MatConstIterator_ < _Tp > begin ( ) const ;
template < typename _Tp > MatConstIterator_ < _Tp > end ( ) const ;
2010-10-18 10:51:46 +02:00
enum { MAGIC_VAL = 0x42FF0000 , AUTO_STEP = 0 , CONTINUOUS_FLAG = CV_MAT_CONT_FLAG , SUBMATRIX_FLAG = CV_SUBMAT_FLAG } ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
/*! includes several bit-fields:
- the magic signature
- continuity flag
- depth
- number of channels
*/
2010-05-11 19:44:00 +02:00
int flags ;
2010-11-23 17:39:20 +01:00
//! the matrix dimensionality, >= 2
2010-10-12 14:31:40 +02:00
int dims ;
//! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
2010-05-11 19:44:00 +02:00
int rows , cols ;
2010-05-18 17:41:28 +02:00
//! pointer to the data
2010-05-11 19:44:00 +02:00
uchar * data ;
2010-05-18 17:41:28 +02:00
//! pointer to the reference counter;
2010-05-11 19:44:00 +02:00
// when matrix points to user-allocated data, the pointer is NULL
int * refcount ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! helper fields used in locateROI and adjustROI
2010-05-11 19:44:00 +02:00
uchar * datastart ;
uchar * dataend ;
2010-10-18 10:51:46 +02:00
uchar * datalimit ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! custom allocator
2010-10-19 13:57:37 +02:00
MatAllocator * allocator ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
struct CV_EXPORTS MSize
{
MSize ( int * _p ) ;
Size operator ( ) ( ) const ;
2010-12-28 22:15:58 +01:00
const int & operator [ ] ( int i ) const ;
2010-10-12 14:31:40 +02:00
int & operator [ ] ( int i ) ;
operator const int * ( ) const ;
bool operator = = ( const MSize & sz ) const ;
bool operator ! = ( const MSize & sz ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
int * p ;
} ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
struct CV_EXPORTS MStep
{
MStep ( ) ;
MStep ( size_t s ) ;
2010-12-28 22:15:58 +01:00
const size_t & operator [ ] ( int i ) const ;
2010-10-12 14:31:40 +02:00
size_t & operator [ ] ( int i ) ;
operator size_t ( ) const ;
MStep & operator = ( size_t s ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
size_t * p ;
size_t buf [ 2 ] ;
protected :
MStep & operator = ( const MStep & ) ;
} ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
MSize size ;
MStep step ;
2012-05-28 13:22:43 +02:00
2012-04-13 23:50:59 +02:00
protected :
void initEmpty ( ) ;
2010-05-11 19:44:00 +02:00
} ;
2011-04-17 15:14:45 +02:00
2010-05-18 17:41:28 +02:00
/*!
Random Number Generator
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
The class implements RNG using Multiply - with - Carry algorithm
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS RNG
{
public :
2010-12-10 20:06:38 +01:00
enum { UNIFORM = 0 , NORMAL = 1 } ;
2010-05-11 19:44:00 +02:00
RNG ( ) ;
2012-05-28 13:22:43 +02:00
RNG ( uint64 state ) ;
2010-05-18 17:41:28 +02:00
//! updates the state and returns the next 32-bit unsigned integer random number
2010-05-11 19:44:00 +02:00
unsigned next ( ) ;
operator uchar ( ) ;
operator schar ( ) ;
operator ushort ( ) ;
operator short ( ) ;
operator unsigned ( ) ;
2011-04-17 15:14:45 +02:00
//! returns a random integer sampled uniformly from [0, N).
2012-05-28 13:22:43 +02:00
unsigned operator ( ) ( unsigned N ) ;
2011-04-17 15:14:45 +02:00
unsigned operator ( ) ( ) ;
2010-05-11 19:44:00 +02:00
operator int ( ) ;
operator float ( ) ;
operator double ( ) ;
2010-05-18 17:41:28 +02:00
//! returns uniformly distributed integer random number from [a,b) range
2010-05-11 19:44:00 +02:00
int uniform ( int a , int b ) ;
2010-05-18 17:41:28 +02:00
//! returns uniformly distributed floating-point random number from [a,b) range
2010-05-11 19:44:00 +02:00
float uniform ( float a , float b ) ;
2010-05-18 17:41:28 +02:00
//! returns uniformly distributed double-precision floating-point random number from [a,b) range
2010-05-11 19:44:00 +02:00
double uniform ( double a , double b ) ;
2012-03-29 14:00:34 +02:00
void fill ( InputOutputArray mat , int distType , InputArray a , InputArray b , bool saturateRange = false ) ;
2011-04-17 15:14:45 +02:00
//! returns Gaussian random variate with mean zero.
double gaussian ( double sigma ) ;
2010-05-11 19:44:00 +02:00
uint64 state ;
} ;
2010-10-19 13:57:37 +02:00
2013-03-05 23:51:19 +01:00
class CV_EXPORTS RNG_MT19937
{
public :
RNG_MT19937 ( ) ;
RNG_MT19937 ( unsigned s ) ;
void seed ( unsigned s ) ;
unsigned next ( ) ;
operator int ( ) ;
operator unsigned ( ) ;
operator float ( ) ;
operator double ( ) ;
unsigned operator ( ) ( unsigned N ) ;
unsigned operator ( ) ( ) ;
// returns uniformly distributed integer random number from [a,b) range
int uniform ( int a , int b ) ;
// returns uniformly distributed floating-point random number from [a,b) range
float uniform ( float a , float b ) ;
// returns uniformly distributed double-precision floating-point random number from [a,b) range
double uniform ( double a , double b ) ;
private :
enum PeriodParameters { N = 624 , M = 397 } ;
unsigned state [ N ] ;
int mti ;
} ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
/*!
Termination criteria in iterative algorithms
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS TermCriteria
{
public :
2010-05-25 16:57:10 +02:00
enum
{
COUNT = 1 , //!< the maximum number of iterations or elements to compute
MAX_ITER = COUNT , //!< ditto
EPS = 2 //!< the desired accuracy or change in parameters at which the iterative algorithm stops
} ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! default constructor
2010-05-11 19:44:00 +02:00
TermCriteria ( ) ;
2010-05-25 16:57:10 +02:00
//! full constructor
2013-02-01 07:16:30 +01:00
TermCriteria ( int type , int maxCount , double epsilon ) ;
2010-05-25 16:57:10 +02:00
//! conversion from CvTermCriteria
2010-05-11 19:44:00 +02:00
TermCriteria ( const CvTermCriteria & criteria ) ;
2013-02-01 07:16:30 +01:00
//! conversion to CvTermCriteria
2010-05-11 19:44:00 +02:00
operator CvTermCriteria ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
int type ; //!< the type of termination criteria: COUNT, EPS or COUNT + EPS
int maxCount ; // the maximum number of iterations/elements
double epsilon ; // the desired accuracy
2010-05-11 19:44:00 +02:00
} ;
2012-05-28 13:22:43 +02:00
2012-04-30 16:33:52 +02:00
typedef void ( * BinaryFunc ) ( const uchar * src1 , size_t step1 ,
const uchar * src2 , size_t step2 ,
uchar * dst , size_t step , Size sz ,
void * ) ;
CV_EXPORTS BinaryFunc getConvertFunc ( int sdepth , int ddepth ) ;
CV_EXPORTS BinaryFunc getConvertScaleFunc ( int sdepth , int ddepth ) ;
2012-05-28 13:22:43 +02:00
CV_EXPORTS BinaryFunc getCopyMaskFunc ( size_t esz ) ;
2010-10-12 14:31:40 +02:00
//! swaps two matrices
CV_EXPORTS void swap ( Mat & a , Mat & b ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! extracts Channel of Interest from CvMat or IplImage and makes cv::Mat out of it.
2011-04-17 15:14:45 +02:00
CV_EXPORTS void extractImageCOI ( const CvArr * arr , OutputArray coiimg , int coi = - 1 ) ;
2010-05-18 17:41:28 +02:00
//! inserts single-channel cv::Mat into a multi-channel CvMat or IplImage
2012-05-28 13:22:43 +02:00
CV_EXPORTS void insertImageCOI ( InputArray coiimg , CvArr * arr , int coi = - 1 ) ;
2011-06-18 12:56:49 +02:00
2010-10-12 14:31:40 +02:00
//! adds one matrix to another (dst = src1 + src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void add ( InputArray src1 , InputArray src2 , OutputArray dst ,
2011-06-08 08:55:04 +02:00
InputArray mask = noArray ( ) , int dtype = - 1 ) ;
2012-05-28 13:22:43 +02:00
//! subtracts one matrix from another (dst = src1 - src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void subtract ( InputArray src1 , InputArray src2 , OutputArray dst ,
2011-06-08 08:55:04 +02:00
InputArray mask = noArray ( ) , int dtype = - 1 ) ;
2010-10-12 14:31:40 +02:00
//! computes element-wise weighted product of the two arrays (dst = scale*src1*src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void multiply ( InputArray src1 , InputArray src2 ,
2011-04-17 15:14:45 +02:00
OutputArray dst , double scale = 1 , int dtype = - 1 ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! computes element-wise weighted quotient of the two arrays (dst = scale*src1/src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void divide ( InputArray src1 , InputArray src2 , OutputArray dst ,
2011-04-17 15:14:45 +02:00
double scale = 1 , int dtype = - 1 ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! computes element-wise weighted reciprocal of an array (dst = scale/src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void divide ( double scale , InputArray src2 ,
2011-04-17 15:14:45 +02:00
OutputArray dst , int dtype = - 1 ) ;
2010-10-12 14:31:40 +02:00
//! adds scaled array to another one (dst = alpha*src1 + src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void scaleAdd ( InputArray src1 , double alpha , InputArray src2 , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void addWeighted ( InputArray src1 , double alpha , InputArray src2 ,
2011-04-17 15:14:45 +02:00
double beta , double gamma , OutputArray dst , int dtype = - 1 ) ;
2010-10-12 14:31:40 +02:00
//! scales array elements, computes absolute values and converts the results to 8-bit unsigned integers: dst(i)=saturate_cast<uchar>abs(src(i)*alpha+beta)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void convertScaleAbs ( InputArray src , OutputArray dst ,
2011-04-17 15:14:45 +02:00
double alpha = 1 , double beta = 0 ) ;
//! transforms array of numbers using a lookup table: dst(i)=lut(src(i))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void LUT ( InputArray src , InputArray lut , OutputArray dst ,
2011-04-17 15:14:45 +02:00
int interpolation = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! computes sum of array elements
2012-05-28 13:22:43 +02:00
CV_EXPORTS_AS ( sumElems ) Scalar sum ( InputArray src ) ;
2010-05-18 17:41:28 +02:00
//! computes the number of nonzero array elements
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W int countNonZero ( InputArray src ) ;
2012-10-11 20:52:15 +02:00
//! returns the list of locations of non-zero pixels
CV_EXPORTS_W void findNonZero ( InputArray src , OutputArray idx ) ;
2012-10-17 09:12:04 +02:00
2010-05-18 17:41:28 +02:00
//! computes mean value of selected array elements
2011-06-08 08:55:04 +02:00
CV_EXPORTS_W Scalar mean ( InputArray src , InputArray mask = noArray ( ) ) ;
2010-05-18 17:41:28 +02:00
//! computes mean value and standard deviation of all or selected array elements
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void meanStdDev ( InputArray src , OutputArray mean , OutputArray stddev ,
2011-06-08 08:55:04 +02:00
InputArray mask = noArray ( ) ) ;
2010-05-25 16:57:10 +02:00
//! computes norm of the selected array part
2011-06-08 08:55:04 +02:00
CV_EXPORTS_W double norm ( InputArray src1 , int normType = NORM_L2 , InputArray mask = noArray ( ) ) ;
2010-05-18 17:41:28 +02:00
//! computes norm of selected part of the difference between two arrays
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W double norm ( InputArray src1 , InputArray src2 ,
2011-06-08 08:55:04 +02:00
int normType = NORM_L2 , InputArray mask = noArray ( ) ) ;
2012-03-15 15:36:01 +01:00
//! naive nearest neighbor finder
CV_EXPORTS_W void batchDistance ( InputArray src1 , InputArray src2 ,
OutputArray dist , int dtype , OutputArray nidx ,
int normType = NORM_L2 , int K = 0 ,
InputArray mask = noArray ( ) , int update = 0 ,
bool crosscheck = false ) ;
2012-05-28 13:22:43 +02:00
//! scales and shifts array elements so that either the specified norm (alpha) or the minimum (alpha) and maximum (beta) array values get the specified values
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void normalize ( InputArray src , OutputArray dst , double alpha = 1 , double beta = 0 ,
2011-06-08 08:55:04 +02:00
int norm_type = NORM_L2 , int dtype = - 1 , InputArray mask = noArray ( ) ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! finds global minimum and maximum array elements and returns their values and their locations
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void minMaxLoc ( InputArray src , CV_OUT double * minVal ,
2011-04-17 15:14:45 +02:00
CV_OUT double * maxVal = 0 , CV_OUT Point * minLoc = 0 ,
2011-06-08 08:55:04 +02:00
CV_OUT Point * maxLoc = 0 , InputArray mask = noArray ( ) ) ;
2011-06-06 16:51:27 +02:00
CV_EXPORTS void minMaxIdx ( InputArray src , double * minVal , double * maxVal ,
2011-06-08 08:55:04 +02:00
int * minIdx = 0 , int * maxIdx = 0 , InputArray mask = noArray ( ) ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! transforms 2D matrix to 1D row or column vector by taking sum, minimum, maximum or mean value over all the rows
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void reduce ( InputArray src , OutputArray dst , int dim , int rtype , int dtype = - 1 ) ;
2011-04-17 15:14:45 +02:00
2010-05-25 16:57:10 +02:00
//! makes multi-channel array out of several single-channel arrays
2011-04-17 15:14:45 +02:00
CV_EXPORTS void merge ( const Mat * mv , size_t count , OutputArray dst ) ;
2010-11-23 17:39:20 +01:00
//! makes multi-channel array out of several single-channel arrays
2012-05-11 15:36:48 +02:00
CV_EXPORTS_W void merge ( InputArrayOfArrays mv , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! copies each plane of a multi-channel array to a dedicated array
2010-10-27 20:26:39 +02:00
CV_EXPORTS void split ( const Mat & src , Mat * mvbegin ) ;
2010-11-23 17:39:20 +01:00
//! copies each plane of a multi-channel array to a dedicated array
2012-05-11 15:36:48 +02:00
CV_EXPORTS_W void split ( InputArray m , OutputArrayOfArrays mv ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! copies selected channels from the input arrays to the selected channels of the output arrays
2010-10-27 20:26:39 +02:00
CV_EXPORTS void mixChannels ( const Mat * src , size_t nsrcs , Mat * dst , size_t ndsts ,
const int * fromTo , size_t npairs ) ;
2013-02-24 17:14:01 +01:00
CV_EXPORTS void mixChannels ( const std : : vector < Mat > & src , std : : vector < Mat > & dst ,
2011-04-17 15:14:45 +02:00
const int * fromTo , size_t npairs ) ;
2011-08-08 09:08:58 +02:00
CV_EXPORTS_W void mixChannels ( InputArrayOfArrays src , InputArrayOfArrays dst ,
2013-02-24 17:14:01 +01:00
const std : : vector < int > & fromTo ) ;
2010-10-27 20:26:39 +02:00
2011-06-18 12:56:49 +02:00
//! extracts a single channel from src (coi is 0-based index)
CV_EXPORTS_W void extractChannel ( InputArray src , OutputArray dst , int coi ) ;
//! inserts a single channel to dst (coi is 0-based index)
CV_EXPORTS_W void insertChannel ( InputArray src , InputOutputArray dst , int coi ) ;
2012-05-28 13:22:43 +02:00
2010-05-18 17:41:28 +02:00
//! reverses the order of the rows, columns or both in a matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void flip ( InputArray src , OutputArray dst , int flipCode ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! replicates the input matrix the specified number of times in the horizontal and/or vertical direction
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void repeat ( InputArray src , int ny , int nx , OutputArray dst ) ;
2010-11-23 17:39:20 +01:00
CV_EXPORTS Mat repeat ( const Mat & src , int ny , int nx ) ;
2012-05-28 13:22:43 +02:00
2011-04-17 15:14:45 +02:00
CV_EXPORTS void hconcat ( const Mat * src , size_t nsrc , OutputArray dst ) ;
2011-06-06 16:51:27 +02:00
CV_EXPORTS void hconcat ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2012-04-30 16:33:52 +02:00
CV_EXPORTS_W void hconcat ( InputArrayOfArrays src , OutputArray dst ) ;
2010-05-11 19:44:00 +02:00
2011-04-17 15:14:45 +02:00
CV_EXPORTS void vconcat ( const Mat * src , size_t nsrc , OutputArray dst ) ;
2011-06-06 16:51:27 +02:00
CV_EXPORTS void vconcat ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2012-04-30 16:33:52 +02:00
CV_EXPORTS_W void vconcat ( InputArrayOfArrays src , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! computes bitwise conjunction of the two arrays (dst = src1 & src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void bitwise_and ( InputArray src1 , InputArray src2 ,
2011-06-08 08:55:04 +02:00
OutputArray dst , InputArray mask = noArray ( ) ) ;
2010-10-12 14:31:40 +02:00
//! computes bitwise disjunction of the two arrays (dst = src1 | src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void bitwise_or ( InputArray src1 , InputArray src2 ,
2011-06-08 08:55:04 +02:00
OutputArray dst , InputArray mask = noArray ( ) ) ;
2010-10-12 14:31:40 +02:00
//! computes bitwise exclusive-or of the two arrays (dst = src1 ^ src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void bitwise_xor ( InputArray src1 , InputArray src2 ,
2011-06-08 08:55:04 +02:00
OutputArray dst , InputArray mask = noArray ( ) ) ;
2010-10-12 14:31:40 +02:00
//! inverts each bit of array (dst = ~src)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void bitwise_not ( InputArray src , OutputArray dst ,
2011-06-08 08:55:04 +02:00
InputArray mask = noArray ( ) ) ;
2010-10-12 14:31:40 +02:00
//! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void absdiff ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
//! set mask elements for those array elements which are within the element-specific bounding box (dst = lowerb <= src && src < upperb)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void inRange ( InputArray src , InputArray lowerb ,
2012-05-28 13:22:43 +02:00
InputArray upperb , OutputArray dst ) ;
2010-10-12 14:31:40 +02:00
//! compares elements of two arrays (dst = src1 <cmpop> src2)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void compare ( InputArray src1 , InputArray src2 , OutputArray dst , int cmpop ) ;
2010-10-12 14:31:40 +02:00
//! computes per-element minimum of two arrays (dst = min(src1, src2))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void min ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2011-04-17 15:14:45 +02:00
//! computes per-element maximum of two arrays (dst = max(src1, src2))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void max ( InputArray src1 , InputArray src2 , OutputArray dst ) ;
2011-04-17 15:14:45 +02:00
//! computes per-element minimum of two arrays (dst = min(src1, src2))
CV_EXPORTS void min ( const Mat & src1 , const Mat & src2 , Mat & dst ) ;
2010-10-12 14:31:40 +02:00
//! computes per-element minimum of array and scalar (dst = min(src1, src2))
2011-04-17 15:14:45 +02:00
CV_EXPORTS void min ( const Mat & src1 , double src2 , Mat & dst ) ;
2010-10-12 14:31:40 +02:00
//! computes per-element maximum of two arrays (dst = max(src1, src2))
2011-04-17 15:14:45 +02:00
CV_EXPORTS void max ( const Mat & src1 , const Mat & src2 , Mat & dst ) ;
2010-10-12 14:31:40 +02:00
//! computes per-element maximum of array and scalar (dst = max(src1, src2))
2012-05-28 13:22:43 +02:00
CV_EXPORTS void max ( const Mat & src1 , double src2 , Mat & dst ) ;
2010-10-12 14:31:40 +02:00
//! computes square root of each matrix element (dst = src**0.5)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void sqrt ( InputArray src , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
//! raises the input matrix elements to the specified power (b = a**power)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void pow ( InputArray src , double power , OutputArray dst ) ;
2010-10-12 14:31:40 +02:00
//! computes exponent of each matrix element (dst = e**src)
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void exp ( InputArray src , OutputArray dst ) ;
2010-10-12 14:31:40 +02:00
//! computes natural logarithm of absolute value of each matrix element: dst = log(abs(src))
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void log ( InputArray src , OutputArray dst ) ;
2010-05-21 22:37:05 +02:00
//! computes cube root of the argument
2010-10-27 20:26:39 +02:00
CV_EXPORTS_W float cubeRoot ( float val ) ;
2010-05-21 22:37:05 +02:00
//! computes the angle in degrees (0..360) of the vector (x,y)
2010-10-27 20:26:39 +02:00
CV_EXPORTS_W float fastAtan2 ( float y , float x ) ;
2012-01-24 21:14:07 +01:00
CV_EXPORTS void exp ( const float * src , float * dst , int n ) ;
CV_EXPORTS void log ( const float * src , float * dst , int n ) ;
CV_EXPORTS void fastAtan2 ( const float * y , const float * x , float * dst , int n , bool angleInDegrees ) ;
2012-05-28 13:22:43 +02:00
CV_EXPORTS void magnitude ( const float * x , const float * y , float * dst , int n ) ;
2010-05-21 22:37:05 +02:00
//! converts polar coordinates to Cartesian
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void polarToCart ( InputArray magnitude , InputArray angle ,
2011-04-17 15:14:45 +02:00
OutputArray x , OutputArray y , bool angleInDegrees = false ) ;
2010-05-21 22:37:05 +02:00
//! converts Cartesian coordinates to polar
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void cartToPolar ( InputArray x , InputArray y ,
2011-04-17 15:14:45 +02:00
OutputArray magnitude , OutputArray angle ,
bool angleInDegrees = false ) ;
2010-05-21 22:37:05 +02:00
//! computes angle (angle(i)) of each (x(i), y(i)) vector
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void phase ( InputArray x , InputArray y , OutputArray angle ,
2010-10-27 20:26:39 +02:00
bool angleInDegrees = false ) ;
2010-05-21 22:37:05 +02:00
//! computes magnitude (magnitude(i)) of each (x(i), y(i)) vector
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void magnitude ( InputArray x , InputArray y , OutputArray magnitude ) ;
2010-05-21 22:37:05 +02:00
//! checks that each matrix element is within the specified range.
2012-03-15 16:21:33 +01:00
CV_EXPORTS_W bool checkRange ( InputArray a , bool quiet = true , CV_OUT Point * pos = 0 ,
2010-10-27 20:26:39 +02:00
double minVal = - DBL_MAX , double maxVal = DBL_MAX ) ;
2012-04-30 16:33:52 +02:00
//! converts NaN's to the given number
CV_EXPORTS_W void patchNaNs ( InputOutputArray a , double val = 0 ) ;
2012-05-28 13:22:43 +02:00
2010-05-21 22:37:05 +02:00
//! implements generalized matrix product algorithm GEMM from BLAS
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void gemm ( InputArray src1 , InputArray src2 , double alpha ,
InputArray src3 , double gamma , OutputArray dst , int flags = 0 ) ;
2010-05-21 22:37:05 +02:00
//! multiplies matrix by its transposition from the left or from the right
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void mulTransposed ( InputArray src , OutputArray dst , bool aTa ,
2011-06-08 08:55:04 +02:00
InputArray delta = noArray ( ) ,
2011-04-17 15:14:45 +02:00
double scale = 1 , int dtype = - 1 ) ;
2010-05-21 22:37:05 +02:00
//! transposes the matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void transpose ( InputArray src , OutputArray dst ) ;
2010-05-21 22:37:05 +02:00
//! performs affine transformation of each element of multi-channel input matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void transform ( InputArray src , OutputArray dst , InputArray m ) ;
2010-05-21 22:37:05 +02:00
//! performs perspective transformation of each element of multi-channel input matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void perspectiveTransform ( InputArray src , OutputArray dst , InputArray m ) ;
2010-05-11 19:44:00 +02:00
2012-05-28 13:22:43 +02:00
//! extends the symmetrical matrix from the lower half or from the upper half
2011-04-17 15:14:45 +02:00
CV_EXPORTS_W void completeSymm ( InputOutputArray mtx , bool lowerToUpper = false ) ;
2010-05-21 22:37:05 +02:00
//! initializes scaled identity matrix
2011-04-17 15:14:45 +02:00
CV_EXPORTS_W void setIdentity ( InputOutputArray mtx , const Scalar & s = Scalar ( 1 ) ) ;
2010-05-21 22:37:05 +02:00
//! computes determinant of a square matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W double determinant ( InputArray mtx ) ;
2010-05-21 22:37:05 +02:00
//! computes trace of a matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W Scalar trace ( InputArray mtx ) ;
2010-05-21 22:37:05 +02:00
//! computes inverse or pseudo-inverse matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W double invert ( InputArray src , OutputArray dst , int flags = DECOMP_LU ) ;
2010-05-21 22:37:05 +02:00
//! solves linear system or a least-square problem
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W bool solve ( InputArray src1 , InputArray src2 ,
2011-04-17 15:14:45 +02:00
OutputArray dst , int flags = DECOMP_LU ) ;
2011-07-19 14:27:07 +02:00
enum
{
2012-10-02 12:34:17 +02:00
SORT_EVERY_ROW = 0 ,
SORT_EVERY_COLUMN = 1 ,
SORT_ASCENDING = 0 ,
SORT_DESCENDING = 16
2011-07-19 14:27:07 +02:00
} ;
2010-05-21 22:37:05 +02:00
//! sorts independently each matrix row or each matrix column
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void sort ( InputArray src , OutputArray dst , int flags ) ;
2010-05-21 22:37:05 +02:00
//! sorts independently each matrix row or each matrix column
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void sortIdx ( InputArray src , OutputArray dst , int flags ) ;
2010-05-21 22:37:05 +02:00
//! finds real roots of a cubic polynomial
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W int solveCubic ( InputArray coeffs , OutputArray roots ) ;
2010-05-21 22:37:05 +02:00
//! finds real and complex roots of a polynomial
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W double solvePoly ( InputArray coeffs , OutputArray roots , int maxIters = 300 ) ;
2010-05-25 16:57:10 +02:00
//! finds eigenvalues of a symmetric matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS bool eigen ( InputArray src , OutputArray eigenvalues , int lowindex = - 1 ,
2010-05-11 19:44:00 +02:00
int highindex = - 1 ) ;
2010-05-25 16:57:10 +02:00
//! finds eigenvalues and eigenvectors of a symmetric matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS bool eigen ( InputArray src , OutputArray eigenvalues ,
2011-04-17 15:14:45 +02:00
OutputArray eigenvectors ,
2010-05-11 19:44:00 +02:00
int lowindex = - 1 , int highindex = - 1 ) ;
2011-07-18 18:31:30 +02:00
CV_EXPORTS_W bool eigen ( InputArray src , bool computeEigenvectors ,
OutputArray eigenvalues , OutputArray eigenvectors ) ;
2011-07-19 14:27:07 +02:00
enum
{
2012-10-02 12:34:17 +02:00
COVAR_SCRAMBLED = 0 ,
COVAR_NORMAL = 1 ,
COVAR_USE_AVG = 2 ,
COVAR_SCALE = 4 ,
COVAR_ROWS = 8 ,
COVAR_COLS = 16
2011-07-19 14:27:07 +02:00
} ;
2010-05-25 16:57:10 +02:00
//! computes covariation matrix of a set of samples
2010-10-27 20:26:39 +02:00
CV_EXPORTS void calcCovarMatrix ( const Mat * samples , int nsamples , Mat & covar , Mat & mean ,
2010-05-11 19:44:00 +02:00
int flags , int ctype = CV_64F ) ;
2010-05-25 16:57:10 +02:00
//! computes covariation matrix of a set of samples
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void calcCovarMatrix ( InputArray samples , OutputArray covar ,
2011-04-17 15:14:45 +02:00
OutputArray mean , int flags , int ctype = CV_64F ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
/*!
Principal Component Analysis
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class PCA is used to compute the special basis for a set of vectors .
The basis will consist of eigenvectors of the covariance matrix computed
from the input set of vectors . After PCA is performed , vectors can be transformed from
the original high - dimensional space to the subspace formed by a few most
prominent eigenvectors ( called the principal components ) ,
corresponding to the largest eigenvalues of the covariation matrix .
Thus the dimensionality of the vector and the correlation between the coordinates is reduced .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The following sample is the function that takes two matrices . The first one stores the set
of vectors ( a row per vector ) that is used to compute PCA , the second one stores another
" test " set of vectors ( a row per vector ) that are first compressed with PCA ,
then reconstructed back and then the reconstruction error norm is computed and printed for each vector .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
using namespace cv ;
PCA compressPCA ( const Mat & pcaset , int maxComponents ,
const Mat & testset , Mat & compressed )
{
PCA pca ( pcaset , // pass the data
Mat ( ) , // we do not have a pre-computed mean vector,
// so let the PCA engine to compute it
CV_PCA_DATA_AS_ROW , // indicate that the vectors
// are stored as matrix rows
// (use CV_PCA_DATA_AS_COL if the vectors are
// the matrix columns)
maxComponents // specify, how many principal components to retain
) ;
// if there is no test data, just return the computed basis, ready-to-use
if ( ! testset . data )
return pca ;
CV_Assert ( testset . cols = = pcaset . cols ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
compressed . create ( testset . rows , maxComponents , testset . type ( ) ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
Mat reconstructed ;
for ( int i = 0 ; i < testset . rows ; i + + )
{
Mat vec = testset . row ( i ) , coeffs = compressed . row ( i ) , reconstructed ;
// compress the vector, the result will be stored
// in the i-th row of the output matrix
pca . project ( vec , coeffs ) ;
// and then reconstruct it
pca . backProject ( coeffs , reconstructed ) ;
// and measure the error
printf ( " %d. diff = %g \n " , i , norm ( vec , reconstructed , NORM_L2 ) ) ;
}
return pca ;
}
\ endcode
*/
2010-11-02 18:58:22 +01:00
class CV_EXPORTS PCA
2010-05-11 19:44:00 +02:00
{
public :
2010-05-25 16:57:10 +02:00
//! default constructor
2010-11-02 18:58:22 +01:00
PCA ( ) ;
2010-05-25 16:57:10 +02:00
//! the constructor that performs PCA
2011-06-06 16:51:27 +02:00
PCA ( InputArray data , InputArray mean , int flags , int maxComponents = 0 ) ;
2012-08-23 05:21:49 +02:00
PCA ( InputArray data , InputArray mean , int flags , double retainedVariance ) ;
2010-05-25 16:57:10 +02:00
//! operator that performs PCA. The previously stored data, if any, is released
2011-06-06 16:51:27 +02:00
PCA & operator ( ) ( InputArray data , InputArray mean , int flags , int maxComponents = 0 ) ;
2012-08-23 05:21:49 +02:00
PCA & operator ( ) ( InputArray data , InputArray mean , int flags , double retainedVariance ) ;
2010-05-25 16:57:10 +02:00
//! projects vector from the original space to the principal components subspace
2011-06-06 16:51:27 +02:00
Mat project ( InputArray vec ) const ;
2010-05-25 16:57:10 +02:00
//! projects vector from the original space to the principal components subspace
2011-06-06 16:51:27 +02:00
void project ( InputArray vec , OutputArray result ) const ;
2010-05-25 16:57:10 +02:00
//! reconstructs the original vector from the projection
2011-06-06 16:51:27 +02:00
Mat backProject ( InputArray vec ) const ;
2010-05-25 16:57:10 +02:00
//! reconstructs the original vector from the projection
2011-06-06 16:51:27 +02:00
void backProject ( InputArray vec , OutputArray result ) const ;
2010-05-11 19:44:00 +02:00
2010-11-02 18:58:22 +01:00
Mat eigenvectors ; //!< eigenvectors of the covariation matrix
Mat eigenvalues ; //!< eigenvalues of the covariation matrix
Mat mean ; //!< mean value subtracted before the projection and added after the back projection
2010-05-11 19:44:00 +02:00
} ;
2013-03-14 11:49:15 +01:00
CV_EXPORTS_W void PCACompute ( InputArray data , InputOutputArray mean ,
2011-07-18 18:31:30 +02:00
OutputArray eigenvectors , int maxComponents = 0 ) ;
2012-05-28 13:22:43 +02:00
2013-03-14 11:49:15 +01:00
CV_EXPORTS_W void PCACompute ( InputArray data , InputOutputArray mean ,
2012-08-23 05:21:49 +02:00
OutputArray eigenvectors , double retainedVariance ) ;
2011-07-18 18:31:30 +02:00
CV_EXPORTS_W void PCAProject ( InputArray data , InputArray mean ,
InputArray eigenvectors , OutputArray result ) ;
CV_EXPORTS_W void PCABackProject ( InputArray data , InputArray mean ,
InputArray eigenvectors , OutputArray result ) ;
2010-05-25 16:57:10 +02:00
/*!
Singular Value Decomposition class
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class is used to compute Singular Value Decomposition of a floating - point matrix and then
use it to solve least - square problems , under - determined linear systems , invert matrices ,
compute condition numbers etc .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
For a bit faster operation you can pass flags = SVD : : MODIFY_A | . . . to modify the decomposed matrix
when it is not necessarily to preserve it . If you want to compute condition number of a matrix
or absolute value of its determinant - you do not need SVD : : u or SVD : : vt ,
so you can pass flags = SVD : : NO_UV | . . . . Another flag SVD : : FULL_UV indicates that the full - size SVD : : u and SVD : : vt
must be computed , which is not necessary most of the time .
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS SVD
{
public :
enum { MODIFY_A = 1 , NO_UV = 2 , FULL_UV = 4 } ;
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-05-11 19:44:00 +02:00
SVD ( ) ;
2010-05-25 16:57:10 +02:00
//! the constructor that performs SVD
2011-06-06 16:51:27 +02:00
SVD ( InputArray src , int flags = 0 ) ;
2010-05-25 16:57:10 +02:00
//! the operator that performs SVD. The previously allocated SVD::u, SVD::w are SVD::vt are released.
2011-06-06 16:51:27 +02:00
SVD & operator ( ) ( InputArray src , int flags = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-08-30 20:05:05 +02:00
//! decomposes matrix and stores the results to user-provided matrices
2011-06-06 16:51:27 +02:00
static void compute ( InputArray src , OutputArray w ,
2011-04-17 15:14:45 +02:00
OutputArray u , OutputArray vt , int flags = 0 ) ;
2010-08-30 20:05:05 +02:00
//! computes singular values of a matrix
2011-06-06 16:51:27 +02:00
static void compute ( InputArray src , OutputArray w , int flags = 0 ) ;
2010-08-30 20:05:05 +02:00
//! performs back substitution
2011-06-06 16:51:27 +02:00
static void backSubst ( InputArray w , InputArray u ,
InputArray vt , InputArray rhs ,
2011-04-17 15:14:45 +02:00
OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
2010-08-30 20:05:05 +02:00
template < typename _Tp , int m , int n , int nm > static void compute ( const Matx < _Tp , m , n > & a ,
Matx < _Tp , nm , 1 > & w , Matx < _Tp , m , nm > & u , Matx < _Tp , n , nm > & vt ) ;
template < typename _Tp , int m , int n , int nm > static void compute ( const Matx < _Tp , m , n > & a ,
Matx < _Tp , nm , 1 > & w ) ;
template < typename _Tp , int m , int n , int nm , int nb > static void backSubst ( const Matx < _Tp , nm , 1 > & w ,
const Matx < _Tp , m , nm > & u , const Matx < _Tp , n , nm > & vt , const Matx < _Tp , m , nb > & rhs , Matx < _Tp , n , nb > & dst ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! finds dst = arg min_{|dst|=1} |m*dst|
2011-06-06 16:51:27 +02:00
static void solveZ ( InputArray src , OutputArray dst ) ;
2012-05-28 13:22:43 +02:00
//! performs back substitution, so that dst is the solution or pseudo-solution of m*dst = rhs, where m is the decomposed matrix
2011-06-06 16:51:27 +02:00
void backSubst ( InputArray rhs , OutputArray dst ) const ;
2010-05-11 19:44:00 +02:00
Mat u , w , vt ;
} ;
2011-07-18 18:31:30 +02:00
//! computes SVD of src
2013-03-14 11:49:15 +01:00
CV_EXPORTS_W void SVDecomp ( InputArray src , OutputArray w , OutputArray u , OutputArray vt , int flags = 0 ) ;
2011-07-18 18:31:30 +02:00
//! performs back substitution for the previously computed SVD
CV_EXPORTS_W void SVBackSubst ( InputArray w , InputArray u , InputArray vt ,
2013-03-14 11:49:15 +01:00
InputArray rhs , OutputArray dst ) ;
2011-07-18 18:31:30 +02:00
2010-05-25 16:57:10 +02:00
//! computes Mahalanobis distance between two vectors: sqrt((v1-v2)'*icovar*(v1-v2)), where icovar is the inverse covariation matrix
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W double Mahalanobis ( InputArray v1 , InputArray v2 , InputArray icovar ) ;
2010-05-25 16:57:10 +02:00
//! a synonym for Mahalanobis
2011-06-06 16:51:27 +02:00
CV_EXPORTS double Mahalonobis ( InputArray v1 , InputArray v2 , InputArray icovar ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! performs forward or inverse 1D or 2D Discrete Fourier Transformation
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void dft ( InputArray src , OutputArray dst , int flags = 0 , int nonzeroRows = 0 ) ;
2010-05-25 16:57:10 +02:00
//! performs inverse 1D or 2D Discrete Fourier Transformation
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void idft ( InputArray src , OutputArray dst , int flags = 0 , int nonzeroRows = 0 ) ;
2010-05-25 16:57:10 +02:00
//! performs forward or inverse 1D or 2D Discrete Cosine Transformation
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void dct ( InputArray src , OutputArray dst , int flags = 0 ) ;
2010-05-25 16:57:10 +02:00
//! performs inverse 1D or 2D Discrete Cosine Transformation
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void idct ( InputArray src , OutputArray dst , int flags = 0 ) ;
2010-05-25 16:57:10 +02:00
//! computes element-wise product of the two Fourier spectrums. The second spectrum can optionally be conjugated before the multiplication
2011-06-06 16:51:27 +02:00
CV_EXPORTS_W void mulSpectrums ( InputArray a , InputArray b , OutputArray c ,
2011-04-17 15:14:45 +02:00
int flags , bool conjB = false ) ;
2010-05-25 16:57:10 +02:00
//! computes the minimal vector size vecsize1 >= vecsize so that the dft() of the vector of length vecsize1 can be computed efficiently
2010-10-27 20:26:39 +02:00
CV_EXPORTS_W int getOptimalDFTSize ( int vecsize ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
/*!
Various k - Means flags
*/
enum
{
KMEANS_RANDOM_CENTERS = 0 , // Chooses random centers for k-Means initialization
KMEANS_PP_CENTERS = 2 , // Uses k-Means++ algorithm for initialization
KMEANS_USE_INITIAL_LABELS = 1 // Uses the user-provided labels for K-Means initialization
} ;
//! clusters the input data using k-Means algorithm
2013-03-14 11:49:15 +01:00
CV_EXPORTS_W double kmeans ( InputArray data , int K , InputOutputArray bestLabels ,
2011-04-17 15:14:45 +02:00
TermCriteria criteria , int attempts ,
2011-06-08 08:55:04 +02:00
int flags , OutputArray centers = noArray ( ) ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! returns the thread-local Random number generator
2010-05-11 19:44:00 +02:00
CV_EXPORTS RNG & theRNG ( ) ;
2010-05-25 16:57:10 +02:00
//! returns the next unifomly-distributed random number of the specified type
2010-05-11 19:44:00 +02:00
template < typename _Tp > static inline _Tp randu ( ) { return ( _Tp ) theRNG ( ) ; }
2010-05-25 16:57:10 +02:00
//! fills array with uniformly-distributed random numbers from the range [low, high)
2011-06-08 00:51:31 +02:00
CV_EXPORTS_W void randu ( InputOutputArray dst , InputArray low , InputArray high ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! fills array with normally-distributed random numbers with the specified mean and the standard deviation
2011-06-08 00:51:31 +02:00
CV_EXPORTS_W void randn ( InputOutputArray dst , InputArray mean , InputArray stddev ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! shuffles the input array elements
2011-04-17 15:14:45 +02:00
CV_EXPORTS void randShuffle ( InputOutputArray dst , double iterFactor = 1. , RNG * rng = 0 ) ;
2011-07-18 18:31:30 +02:00
CV_EXPORTS_AS ( randShuffle ) void randShuffle_ ( InputOutputArray dst , double iterFactor = 1. ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! draws the line segment (pt1, pt2) in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void line ( CV_IN_OUT Mat & img , Point pt1 , Point pt2 , const Scalar & color ,
2010-05-11 19:44:00 +02:00
int thickness = 1 , int lineType = 8 , int shift = 0 ) ;
2010-05-25 16:57:10 +02:00
//! draws the rectangle outline or a solid rectangle with the opposite corners pt1 and pt2 in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void rectangle ( CV_IN_OUT Mat & img , Point pt1 , Point pt2 ,
2010-05-11 19:44:00 +02:00
const Scalar & color , int thickness = 1 ,
int lineType = 8 , int shift = 0 ) ;
2012-05-28 13:22:43 +02:00
//! draws the rectangle outline or a solid rectangle covering rec in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS void rectangle ( CV_IN_OUT Mat & img , Rect rec ,
2010-05-11 19:44:00 +02:00
const Scalar & color , int thickness = 1 ,
int lineType = 8 , int shift = 0 ) ;
2010-05-25 16:57:10 +02:00
//! draws the circle outline or a solid circle in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void circle ( CV_IN_OUT Mat & img , Point center , int radius ,
2010-05-11 19:44:00 +02:00
const Scalar & color , int thickness = 1 ,
int lineType = 8 , int shift = 0 ) ;
2010-05-25 16:57:10 +02:00
//! draws an elliptic arc, ellipse sector or a rotated ellipse in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void ellipse ( CV_IN_OUT Mat & img , Point center , Size axes ,
2010-05-11 19:44:00 +02:00
double angle , double startAngle , double endAngle ,
const Scalar & color , int thickness = 1 ,
int lineType = 8 , int shift = 0 ) ;
2010-05-25 16:57:10 +02:00
//! draws a rotated ellipse in the image
2012-08-08 10:18:52 +02:00
CV_EXPORTS_W void ellipse ( CV_IN_OUT Mat & img , const RotatedRect & box , const Scalar & color ,
2010-05-11 19:44:00 +02:00
int thickness = 1 , int lineType = 8 ) ;
2010-05-25 16:57:10 +02:00
//! draws a filled convex polygon in the image
2010-10-27 20:26:39 +02:00
CV_EXPORTS void fillConvexPoly ( Mat & img , const Point * pts , int npts ,
2010-05-11 19:44:00 +02:00
const Scalar & color , int lineType = 8 ,
int shift = 0 ) ;
2011-07-18 18:31:30 +02:00
CV_EXPORTS_W void fillConvexPoly ( InputOutputArray img , InputArray points ,
const Scalar & color , int lineType = 8 ,
int shift = 0 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! fills an area bounded by one or more polygons
2010-10-27 20:26:39 +02:00
CV_EXPORTS void fillPoly ( Mat & img , const Point * * pts ,
const int * npts , int ncontours ,
2010-05-11 19:44:00 +02:00
const Scalar & color , int lineType = 8 , int shift = 0 ,
Point offset = Point ( ) ) ;
2011-07-18 18:31:30 +02:00
CV_EXPORTS_W void fillPoly ( InputOutputArray img , InputArrayOfArrays pts ,
const Scalar & color , int lineType = 8 , int shift = 0 ,
Point offset = Point ( ) ) ;
2010-05-25 16:57:10 +02:00
//! draws one or more polygonal curves
2012-10-16 17:37:12 +02:00
CV_EXPORTS void polylines ( Mat & img , const Point * const * pts , const int * npts ,
2010-10-12 14:31:40 +02:00
int ncontours , bool isClosed , const Scalar & color ,
int thickness = 1 , int lineType = 8 , int shift = 0 ) ;
2010-05-11 19:44:00 +02:00
2011-07-29 16:31:28 +02:00
CV_EXPORTS_W void polylines ( InputOutputArray img , InputArrayOfArrays pts ,
2011-07-18 18:31:30 +02:00
bool isClosed , const Scalar & color ,
int thickness = 1 , int lineType = 8 , int shift = 0 ) ;
2012-05-28 22:11:38 +02:00
//! draws contours in the image
CV_EXPORTS_W void drawContours ( InputOutputArray image , InputArrayOfArrays contours ,
int contourIdx , const Scalar & color ,
int thickness = 1 , int lineType = 8 ,
InputArray hierarchy = noArray ( ) ,
int maxLevel = INT_MAX , Point offset = Point ( ) ) ;
2010-05-25 16:57:10 +02:00
//! clips the line segment by the rectangle Rect(0, 0, imgSize.width, imgSize.height)
2010-10-27 20:26:39 +02:00
CV_EXPORTS bool clipLine ( Size imgSize , CV_IN_OUT Point & pt1 , CV_IN_OUT Point & pt2 ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! clips the line segment by the rectangle imgRect
2011-07-14 16:13:10 +02:00
CV_EXPORTS_W bool clipLine ( Rect imgRect , CV_OUT CV_IN_OUT Point & pt1 , CV_OUT CV_IN_OUT Point & pt2 ) ;
2010-05-25 16:57:10 +02:00
/*!
Line iterator class
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class is used to iterate over all the pixels on the raster line
segment connecting two specified points .
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS LineIterator
{
public :
2010-05-25 16:57:10 +02:00
//! intializes the iterator
2010-10-12 14:31:40 +02:00
LineIterator ( const Mat & img , Point pt1 , Point pt2 ,
int connectivity = 8 , bool leftToRight = false ) ;
2010-05-25 16:57:10 +02:00
//! returns pointer to the current pixel
2010-05-11 19:44:00 +02:00
uchar * operator * ( ) ;
2010-05-25 16:57:10 +02:00
//! prefix increment operator (++it). shifts iterator to the next pixel
2010-05-11 19:44:00 +02:00
LineIterator & operator + + ( ) ;
2010-05-25 16:57:10 +02:00
//! postfix increment operator (it++). shifts iterator to the next pixel
2010-05-11 19:44:00 +02:00
LineIterator operator + + ( int ) ;
2010-05-25 16:57:10 +02:00
//! returns coordinates of the current pixel
Point pos ( ) const ;
2010-05-11 19:44:00 +02:00
uchar * ptr ;
2010-05-25 16:57:10 +02:00
const uchar * ptr0 ;
int step , elemSize ;
2010-05-11 19:44:00 +02:00
int err , count ;
int minusDelta , plusDelta ;
int minusStep , plusStep ;
} ;
2010-05-25 16:57:10 +02:00
//! converts elliptic arc to a polygonal curve
2010-10-27 20:26:39 +02:00
CV_EXPORTS_W void ellipse2Poly ( Point center , Size axes , int angle ,
2011-04-17 15:14:45 +02:00
int arcStart , int arcEnd , int delta ,
2013-02-24 17:14:01 +01:00
CV_OUT std : : vector < Point > & pts ) ;
2010-05-11 19:44:00 +02:00
enum
{
FONT_HERSHEY_SIMPLEX = 0 ,
FONT_HERSHEY_PLAIN = 1 ,
FONT_HERSHEY_DUPLEX = 2 ,
FONT_HERSHEY_COMPLEX = 3 ,
FONT_HERSHEY_TRIPLEX = 4 ,
FONT_HERSHEY_COMPLEX_SMALL = 5 ,
FONT_HERSHEY_SCRIPT_SIMPLEX = 6 ,
FONT_HERSHEY_SCRIPT_COMPLEX = 7 ,
FONT_ITALIC = 16
} ;
2010-05-25 16:57:10 +02:00
//! renders text string in the image
2013-03-22 17:37:49 +01:00
CV_EXPORTS_W void putText ( Mat & img , const String & text , Point org ,
2010-05-11 19:44:00 +02:00
int fontFace , double fontScale , Scalar color ,
2012-03-15 16:21:33 +01:00
int thickness = 1 , int lineType = 8 ,
2010-05-11 19:44:00 +02:00
bool bottomLeftOrigin = false ) ;
2010-05-25 16:57:10 +02:00
//! returns bounding box of the text string
2013-03-22 17:37:49 +01:00
CV_EXPORTS_W Size getTextSize ( const String & text , int fontFace ,
2010-05-11 19:44:00 +02:00
double fontScale , int thickness ,
2010-10-12 14:31:40 +02:00
CV_OUT int * baseLine ) ;
2010-05-11 19:44:00 +02:00
///////////////////////////////// Mat_<_Tp> ////////////////////////////////////
2010-05-25 16:57:10 +02:00
/*!
Template matrix class derived from Mat
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class Mat_ is a " thin " template wrapper on top of cv : : Mat . It does not have any extra data fields ,
nor it or cv : : Mat have any virtual methods and thus references or pointers to these two classes
can be safely converted one to another . But do it with care , for example :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
// create 100x100 8-bit matrix
Mat M ( 100 , 100 , CV_8U ) ;
// this will compile fine. no any data conversion will be done.
Mat_ < float > & M1 = ( Mat_ < float > & ) M ;
// the program will likely crash at the statement below
M1 ( 99 , 99 ) = 1.f ;
\ endcode
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
While cv : : Mat is sufficient in most cases , cv : : Mat_ can be more convenient if you use a lot of element
access operations and if you know matrix type at compile time .
Note that cv : : Mat : : at < _Tp > ( int y , int x ) and cv : : Mat_ < _Tp > : : operator ( ) ( int y , int x ) do absolutely the
same thing and run at the same speed , but the latter is certainly shorter :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
Mat_ < double > M ( 20 , 20 ) ;
for ( int i = 0 ; i < M . rows ; i + + )
for ( int j = 0 ; j < M . cols ; j + + )
M ( i , j ) = 1. / ( i + j + 1 ) ;
Mat E , V ;
eigen ( M , E , V ) ;
cout < < E . at < double > ( 0 , 0 ) / E . at < double > ( M . rows - 1 , 0 ) ;
\ endcode
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
It is easy to use Mat_ for multi - channel images / matrices - just pass cv : : Vec as cv : : Mat_ template parameter :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
// allocate 320x240 color image and fill it with green (in RGB space)
Mat_ < Vec3b > img ( 240 , 320 , Vec3b ( 0 , 255 , 0 ) ) ;
// now draw a diagonal white line
for ( int i = 0 ; i < 100 ; i + + )
img ( i , i ) = Vec3b ( 255 , 255 , 255 ) ;
// and now modify the 2nd (red) channel of each pixel
for ( int i = 0 ; i < img . rows ; i + + )
for ( int j = 0 ; j < img . cols ; j + + )
img ( i , j ) [ 2 ] ^ = ( uchar ) ( i ^ j ) ; // img(y,x)[c] accesses c-th channel of the pixel (x,y)
\ endcode
*/
2010-05-11 19:44:00 +02:00
template < typename _Tp > class CV_EXPORTS Mat_ : public Mat
{
public :
typedef _Tp value_type ;
typedef typename DataType < _Tp > : : channel_type channel_type ;
typedef MatIterator_ < _Tp > iterator ;
typedef MatConstIterator_ < _Tp > const_iterator ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! default constructor
2010-05-11 19:44:00 +02:00
Mat_ ( ) ;
2010-05-18 17:41:28 +02:00
//! equivalent to Mat(_rows, _cols, DataType<_Tp>::type)
2010-05-11 19:44:00 +02:00
Mat_ ( int _rows , int _cols ) ;
2010-05-25 16:57:10 +02:00
//! constructor that sets each matrix element to specified value
2010-05-11 19:44:00 +02:00
Mat_ ( int _rows , int _cols , const _Tp & value ) ;
2010-05-25 16:57:10 +02:00
//! equivalent to Mat(_size, DataType<_Tp>::type)
2010-05-11 19:44:00 +02:00
explicit Mat_ ( Size _size ) ;
2012-05-28 13:22:43 +02:00
//! constructor that sets each matrix element to specified value
2010-05-11 19:44:00 +02:00
Mat_ ( Size _size , const _Tp & value ) ;
2010-10-12 14:31:40 +02:00
//! n-dim array constructor
Mat_ ( int _ndims , const int * _sizes ) ;
//! n-dim array constructor that sets each matrix element to specified value
Mat_ ( int _ndims , const int * _sizes , const _Tp & value ) ;
2010-05-18 17:41:28 +02:00
//! copy/conversion contructor. If m is of different type, it's converted
2010-05-11 19:44:00 +02:00
Mat_ ( const Mat & m ) ;
2010-05-18 17:41:28 +02:00
//! copy constructor
2010-05-11 19:44:00 +02:00
Mat_ ( const Mat_ & m ) ;
2010-05-25 16:57:10 +02:00
//! constructs a matrix on top of user-allocated data. step is in bytes(!!!), regardless of the type
2010-05-11 19:44:00 +02:00
Mat_ ( int _rows , int _cols , _Tp * _data , size_t _step = AUTO_STEP ) ;
2010-10-12 14:31:40 +02:00
//! constructs n-dim matrix on top of user-allocated data. steps are in bytes(!!!), regardless of the type
Mat_ ( int _ndims , const int * _sizes , _Tp * _data , const size_t * _steps = 0 ) ;
2010-05-25 16:57:10 +02:00
//! selects a submatrix
2010-10-12 14:31:40 +02:00
Mat_ ( const Mat_ & m , const Range & rowRange , const Range & colRange = Range : : all ( ) ) ;
2010-05-25 16:57:10 +02:00
//! selects a submatrix
2010-05-11 19:44:00 +02:00
Mat_ ( const Mat_ & m , const Rect & roi ) ;
2010-10-12 14:31:40 +02:00
//! selects a submatrix, n-dim version
Mat_ ( const Mat_ & m , const Range * ranges ) ;
2011-06-19 23:13:32 +02:00
//! from a matrix expression
explicit Mat_ ( const MatExpr & e ) ;
2010-05-18 17:41:28 +02:00
//! makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column
2013-02-24 17:14:01 +01:00
explicit Mat_ ( const std : : vector < _Tp > & vec , bool copyData = false ) ;
2010-10-20 19:43:46 +02:00
template < int n > explicit Mat_ ( const Vec < typename DataType < _Tp > : : channel_type , n > & vec , bool copyData = true ) ;
template < int m , int n > explicit Mat_ ( const Matx < typename DataType < _Tp > : : channel_type , m , n > & mtx , bool copyData = true ) ;
explicit Mat_ ( const Point_ < typename DataType < _Tp > : : channel_type > & pt , bool copyData = true ) ;
explicit Mat_ ( const Point3_ < typename DataType < _Tp > : : channel_type > & pt , bool copyData = true ) ;
2010-06-09 20:17:50 +02:00
explicit Mat_ ( const MatCommaInitializer_ < _Tp > & commaInitializer ) ;
2010-05-11 19:44:00 +02:00
Mat_ & operator = ( const Mat & m ) ;
Mat_ & operator = ( const Mat_ & m ) ;
2010-05-18 17:41:28 +02:00
//! set all the elements to s.
2010-05-11 19:44:00 +02:00
Mat_ & operator = ( const _Tp & s ) ;
2011-06-19 23:13:32 +02:00
//! assign a matrix expression
Mat_ & operator = ( const MatExpr & e ) ;
2010-05-11 19:44:00 +02:00
2010-05-18 17:41:28 +02:00
//! iterators; they are smart enough to skip gaps in the end of rows
2010-05-11 19:44:00 +02:00
iterator begin ( ) ;
iterator end ( ) ;
const_iterator begin ( ) const ;
const_iterator end ( ) const ;
2010-05-18 17:41:28 +02:00
//! equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type)
2010-05-11 19:44:00 +02:00
void create ( int _rows , int _cols ) ;
2010-05-25 16:57:10 +02:00
//! equivalent to Mat::create(_size, DataType<_Tp>::type)
2010-05-11 19:44:00 +02:00
void create ( Size _size ) ;
2010-10-12 14:31:40 +02:00
//! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)
void create ( int _ndims , const int * _sizes ) ;
2010-05-18 17:41:28 +02:00
//! cross-product
2010-05-11 19:44:00 +02:00
Mat_ cross ( const Mat_ & m ) const ;
2010-05-18 17:41:28 +02:00
//! data type conversion
2010-05-11 19:44:00 +02:00
template < typename T2 > operator Mat_ < T2 > ( ) const ;
2010-05-18 17:41:28 +02:00
//! overridden forms of Mat::row() etc.
2010-05-11 19:44:00 +02:00
Mat_ row ( int y ) const ;
Mat_ col ( int x ) const ;
Mat_ diag ( int d = 0 ) const ;
Mat_ clone ( ) const ;
2010-05-25 16:57:10 +02:00
//! overridden forms of Mat::elemSize() etc.
2010-05-11 19:44:00 +02:00
size_t elemSize ( ) const ;
size_t elemSize1 ( ) const ;
int type ( ) const ;
int depth ( ) const ;
int channels ( ) const ;
2010-10-12 14:31:40 +02:00
size_t step1 ( int i = 0 ) const ;
2010-05-25 16:57:10 +02:00
//! returns step()/sizeof(_Tp)
2010-10-12 14:31:40 +02:00
size_t stepT ( int i = 0 ) const ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! overridden forms of Mat::zeros() etc. Data type is omitted, of course
2010-09-21 17:15:44 +02:00
static MatExpr zeros ( int rows , int cols ) ;
static MatExpr zeros ( Size size ) ;
2010-10-12 14:31:40 +02:00
static MatExpr zeros ( int _ndims , const int * _sizes ) ;
2010-09-21 17:15:44 +02:00
static MatExpr ones ( int rows , int cols ) ;
static MatExpr ones ( Size size ) ;
2010-10-12 14:31:40 +02:00
static MatExpr ones ( int _ndims , const int * _sizes ) ;
2010-09-21 17:15:44 +02:00
static MatExpr eye ( int rows , int cols ) ;
static MatExpr eye ( Size size ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! some more overriden methods
2010-05-11 19:44:00 +02:00
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 ;
2010-10-12 14:31:40 +02:00
Mat_ operator ( ) ( const Range * ranges ) const ;
2010-05-11 19:44:00 +02:00
2012-05-28 13:22:43 +02:00
//! more convenient forms of row and element access operators
2010-05-11 19:44:00 +02:00
_Tp * operator [ ] ( int y ) ;
const _Tp * operator [ ] ( int y ) const ;
2010-10-12 14:31:40 +02:00
//! returns reference to the specified element
_Tp & operator ( ) ( const int * idx ) ;
//! returns read-only reference to the specified element
const _Tp & operator ( ) ( const int * idx ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! returns reference to the specified element
template < int n > _Tp & operator ( ) ( const Vec < int , n > & idx ) ;
//! returns read-only reference to the specified element
template < int n > const _Tp & operator ( ) ( const Vec < int , n > & idx ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! returns reference to the specified element (1D case)
_Tp & operator ( ) ( int idx0 ) ;
//! returns read-only reference to the specified element (1D case)
const _Tp & operator ( ) ( int idx0 ) const ;
//! returns reference to the specified element (2D case)
_Tp & operator ( ) ( int idx0 , int idx1 ) ;
//! returns read-only reference to the specified element (2D case)
const _Tp & operator ( ) ( int idx0 , int idx1 ) const ;
//! returns reference to the specified element (3D case)
_Tp & operator ( ) ( int idx0 , int idx1 , int idx2 ) ;
//! returns read-only reference to the specified element (3D case)
const _Tp & operator ( ) ( int idx0 , int idx1 , int idx2 ) const ;
2012-05-28 13:22:43 +02:00
2010-05-11 19:44:00 +02:00
_Tp & operator ( ) ( Point pt ) ;
const _Tp & operator ( ) ( Point pt ) const ;
2010-05-25 16:57:10 +02:00
//! conversion to vector.
2013-02-24 17:14:01 +01:00
operator std : : vector < _Tp > ( ) const ;
2010-07-29 08:51:19 +02:00
//! conversion to Vec
2010-10-20 19:43:46 +02:00
template < int n > operator Vec < typename DataType < _Tp > : : channel_type , n > ( ) const ;
2010-07-29 08:51:19 +02:00
//! conversion to Matx
2010-10-20 19:43:46 +02:00
template < int m , int n > operator Matx < typename DataType < _Tp > : : channel_type , m , n > ( ) const ;
2010-05-11 19:44:00 +02:00
} ;
typedef Mat_ < uchar > Mat1b ;
typedef Mat_ < Vec2b > Mat2b ;
typedef Mat_ < Vec3b > Mat3b ;
typedef Mat_ < Vec4b > Mat4b ;
typedef Mat_ < short > Mat1s ;
typedef Mat_ < Vec2s > Mat2s ;
typedef Mat_ < Vec3s > Mat3s ;
typedef Mat_ < Vec4s > Mat4s ;
typedef Mat_ < ushort > Mat1w ;
typedef Mat_ < Vec2w > Mat2w ;
typedef Mat_ < Vec3w > Mat3w ;
typedef Mat_ < Vec4w > Mat4w ;
typedef Mat_ < int > Mat1i ;
typedef Mat_ < Vec2i > Mat2i ;
typedef Mat_ < Vec3i > Mat3i ;
typedef Mat_ < Vec4i > Mat4i ;
typedef Mat_ < float > Mat1f ;
typedef Mat_ < Vec2f > Mat2f ;
typedef Mat_ < Vec3f > Mat3f ;
typedef Mat_ < Vec4f > Mat4f ;
typedef Mat_ < double > Mat1d ;
typedef Mat_ < Vec2d > Mat2d ;
typedef Mat_ < Vec3d > Mat3d ;
typedef Mat_ < Vec4d > Mat4d ;
//////////// Iterators & Comma initializers //////////////////
2010-10-12 14:31:40 +02:00
class CV_EXPORTS MatConstIterator
{
public :
typedef uchar * value_type ;
typedef ptrdiff_t difference_type ;
typedef const uchar * * pointer ;
typedef uchar * reference ;
typedef std : : random_access_iterator_tag iterator_category ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! default constructor
MatConstIterator ( ) ;
2012-05-28 13:22:43 +02:00
//! constructor that sets the iterator to the beginning of the matrix
2010-10-12 14:31:40 +02:00
MatConstIterator ( const Mat * _m ) ;
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator ( const Mat * _m , int _row , int _col = 0 ) ;
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator ( const Mat * _m , Point _pt ) ;
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator ( const Mat * _m , const int * _idx ) ;
//! copy constructor
MatConstIterator ( const MatConstIterator & it ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! copy operator
MatConstIterator & operator = ( const MatConstIterator & it ) ;
//! returns the current matrix element
uchar * operator * ( ) const ;
//! returns the i-th matrix element, relative to the current
uchar * operator [ ] ( ptrdiff_t i ) const ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//! shifts the iterator forward by the specified number of elements
MatConstIterator & operator + = ( ptrdiff_t ofs ) ;
//! shifts the iterator backward by the specified number of elements
MatConstIterator & operator - = ( ptrdiff_t ofs ) ;
//! decrements the iterator
MatConstIterator & operator - - ( ) ;
//! decrements the iterator
MatConstIterator operator - - ( int ) ;
//! increments the iterator
MatConstIterator & operator + + ( ) ;
//! increments the iterator
MatConstIterator operator + + ( int ) ;
//! returns the current iterator position
Point pos ( ) const ;
//! returns the current iterator position
void pos ( int * _idx ) const ;
ptrdiff_t lpos ( ) const ;
void seek ( ptrdiff_t ofs , bool relative = false ) ;
void seek ( const int * _idx , bool relative = false ) ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
const Mat * m ;
size_t elemSize ;
uchar * ptr ;
uchar * sliceStart ;
uchar * sliceEnd ;
} ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
/*!
Matrix read - only iterator
2012-05-28 13:22:43 +02:00
*/
2010-05-11 19:44:00 +02:00
template < typename _Tp >
2010-10-12 14:31:40 +02:00
class CV_EXPORTS MatConstIterator_ : public MatConstIterator
2010-05-11 19:44:00 +02:00
{
public :
typedef _Tp value_type ;
2010-10-12 14:31:40 +02:00
typedef ptrdiff_t difference_type ;
2010-07-29 15:52:22 +02:00
typedef const _Tp * pointer ;
typedef const _Tp & reference ;
typedef std : : random_access_iterator_tag iterator_category ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! default constructor
2010-05-11 19:44:00 +02:00
MatConstIterator_ ( ) ;
2012-05-28 13:22:43 +02:00
//! constructor that sets the iterator to the beginning of the matrix
2010-05-11 19:44:00 +02:00
MatConstIterator_ ( const Mat_ < _Tp > * _m ) ;
2010-05-25 16:57:10 +02:00
//! constructor that sets the iterator to the specified element of the matrix
2010-05-11 19:44:00 +02:00
MatConstIterator_ ( const Mat_ < _Tp > * _m , int _row , int _col = 0 ) ;
2010-05-25 16:57:10 +02:00
//! constructor that sets the iterator to the specified element of the matrix
2010-05-11 19:44:00 +02:00
MatConstIterator_ ( const Mat_ < _Tp > * _m , Point _pt ) ;
2010-10-12 14:31:40 +02:00
//! constructor that sets the iterator to the specified element of the matrix
MatConstIterator_ ( const Mat_ < _Tp > * _m , const int * _idx ) ;
2010-05-25 16:57:10 +02:00
//! copy constructor
2010-05-11 19:44:00 +02:00
MatConstIterator_ ( const MatConstIterator_ & it ) ;
2010-05-25 16:57:10 +02:00
//! copy operator
MatConstIterator_ & operator = ( const MatConstIterator_ & it ) ;
//! returns the current matrix element
2010-05-11 19:44:00 +02:00
_Tp operator * ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the i-th matrix element, relative to the current
2010-10-12 14:31:40 +02:00
_Tp operator [ ] ( ptrdiff_t i ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! shifts the iterator forward by the specified number of elements
2010-10-12 14:31:40 +02:00
MatConstIterator_ & operator + = ( ptrdiff_t ofs ) ;
2010-05-25 16:57:10 +02:00
//! shifts the iterator backward by the specified number of elements
2010-10-12 14:31:40 +02:00
MatConstIterator_ & operator - = ( ptrdiff_t ofs ) ;
2010-05-25 16:57:10 +02:00
//! decrements the iterator
2010-05-11 19:44:00 +02:00
MatConstIterator_ & operator - - ( ) ;
2010-05-25 16:57:10 +02:00
//! decrements the iterator
2010-05-11 19:44:00 +02:00
MatConstIterator_ operator - - ( int ) ;
2010-05-25 16:57:10 +02:00
//! increments the iterator
2010-05-11 19:44:00 +02:00
MatConstIterator_ & operator + + ( ) ;
2010-05-25 16:57:10 +02:00
//! increments the iterator
2010-05-11 19:44:00 +02:00
MatConstIterator_ operator + + ( int ) ;
2010-05-25 16:57:10 +02:00
//! returns the current iterator position
2010-05-11 19:44:00 +02:00
Point pos ( ) const ;
} ;
2010-05-25 16:57:10 +02:00
/*!
Matrix read - write iterator
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
*/
2010-05-11 19:44:00 +02:00
template < typename _Tp >
class CV_EXPORTS MatIterator_ : public MatConstIterator_ < _Tp >
{
public :
typedef _Tp * pointer ;
typedef _Tp & reference ;
typedef std : : random_access_iterator_tag iterator_category ;
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-05-11 19:44:00 +02:00
MatIterator_ ( ) ;
2012-05-28 13:22:43 +02:00
//! constructor that sets the iterator to the beginning of the matrix
2010-05-11 19:44:00 +02:00
MatIterator_ ( Mat_ < _Tp > * _m ) ;
2010-05-25 16:57:10 +02:00
//! constructor that sets the iterator to the specified element of the matrix
2010-05-11 19:44:00 +02:00
MatIterator_ ( Mat_ < _Tp > * _m , int _row , int _col = 0 ) ;
2010-05-25 16:57:10 +02:00
//! constructor that sets the iterator to the specified element of the matrix
2010-05-11 19:44:00 +02:00
MatIterator_ ( const Mat_ < _Tp > * _m , Point _pt ) ;
2010-10-12 14:31:40 +02:00
//! constructor that sets the iterator to the specified element of the matrix
MatIterator_ ( const Mat_ < _Tp > * _m , const int * _idx ) ;
2010-05-25 16:57:10 +02:00
//! copy constructor
2010-05-11 19:44:00 +02:00
MatIterator_ ( const MatIterator_ & it ) ;
2010-05-25 16:57:10 +02:00
//! copy operator
2010-05-11 19:44:00 +02:00
MatIterator_ & operator = ( const MatIterator_ < _Tp > & it ) ;
2010-05-25 16:57:10 +02:00
//! returns the current matrix element
2010-05-11 19:44:00 +02:00
_Tp & operator * ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the i-th matrix element, relative to the current
2010-10-12 14:31:40 +02:00
_Tp & operator [ ] ( ptrdiff_t i ) const ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! shifts the iterator forward by the specified number of elements
2010-10-12 14:31:40 +02:00
MatIterator_ & operator + = ( ptrdiff_t ofs ) ;
2010-05-25 16:57:10 +02:00
//! shifts the iterator backward by the specified number of elements
2010-10-12 14:31:40 +02:00
MatIterator_ & operator - = ( ptrdiff_t ofs ) ;
2010-05-25 16:57:10 +02:00
//! decrements the iterator
2010-05-11 19:44:00 +02:00
MatIterator_ & operator - - ( ) ;
2010-05-25 16:57:10 +02:00
//! decrements the iterator
2010-05-11 19:44:00 +02:00
MatIterator_ operator - - ( int ) ;
2010-05-25 16:57:10 +02:00
//! increments the iterator
2010-05-11 19:44:00 +02:00
MatIterator_ & operator + + ( ) ;
2010-05-25 16:57:10 +02:00
//! increments the iterator
2010-05-11 19:44:00 +02:00
MatIterator_ operator + + ( int ) ;
} ;
template < typename _Tp > class CV_EXPORTS MatOp_Iter_ ;
2010-05-25 16:57:10 +02:00
/*!
Comma - separated Matrix Initializer
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class instances are usually not created explicitly .
Instead , they are created on " matrix << firstValue " operator .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The sample below initializes 2 x2 rotation matrix :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
double angle = 30 , a = cos ( angle * CV_PI / 180 ) , b = sin ( angle * CV_PI / 180 ) ;
Mat R = ( Mat_ < double > ( 2 , 2 ) < < a , - b , b , a ) ;
\ endcode
2012-05-28 13:22:43 +02:00
*/
2010-09-21 17:15:44 +02:00
template < typename _Tp > class CV_EXPORTS MatCommaInitializer_
2010-05-11 19:44:00 +02:00
{
public :
2010-05-25 16:57:10 +02:00
//! the constructor, created by "matrix << firstValue" operator, where matrix is cv::Mat
2010-05-11 19:44:00 +02:00
MatCommaInitializer_ ( Mat_ < _Tp > * _m ) ;
2010-05-25 16:57:10 +02:00
//! the operator that takes the next value and put it to the matrix
2010-05-11 19:44:00 +02:00
template < typename T2 > MatCommaInitializer_ < _Tp > & operator , ( T2 v ) ;
2010-05-25 16:57:10 +02:00
//! another form of conversion operator
2010-05-11 19:44:00 +02:00
Mat_ < _Tp > operator * ( ) const ;
2010-09-21 17:15:44 +02:00
operator Mat_ < _Tp > ( ) const ;
protected :
MatIterator_ < _Tp > it ;
2010-05-11 19:44:00 +02:00
} ;
/////////////////////////// multi-dimensional dense matrix //////////////////////////
2010-05-25 16:57:10 +02:00
/*!
n - Dimensional Dense Matrix Iterator Class .
2012-05-28 13:22:43 +02:00
2010-11-23 17:39:20 +01:00
The class cv : : NAryMatIterator is used for iterating over one or more n - dimensional dense arrays ( cv : : Mat ' s ) .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The iterator is completely different from cv : : Mat_ and cv : : SparseMat_ iterators .
It iterates through the slices ( or planes ) , not the elements , where " slice " is a continuous part of the arrays .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
Here is the example on how the iterator can be used to normalize 3 D histogram :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
2010-10-12 14:31:40 +02:00
void normalizeColorHist ( Mat & hist )
2010-05-25 16:57:10 +02:00
{
2012-05-28 13:22:43 +02:00
# if 1
2010-05-25 16:57:10 +02:00
// intialize iterator (the style is different from STL).
// after initialization the iterator will contain
// the number of slices or planes
// the iterator will go through
2010-10-12 14:31:40 +02:00
Mat * arrays [ ] = { & hist , 0 } ;
Mat planes [ 1 ] ;
NAryMatIterator it ( arrays , planes ) ;
2010-05-25 16:57:10 +02:00
double s = 0 ;
// iterate through the matrix. on each iteration
// it.planes[i] (of type Mat) will be set to the current plane of
// i-th n-dim matrix passed to the iterator constructor.
for ( int p = 0 ; p < it . nplanes ; p + + , + + it )
s + = sum ( it . planes [ 0 ] ) [ 0 ] ;
2010-10-12 14:31:40 +02:00
it = NAryMatIterator ( hist ) ;
2010-05-25 16:57:10 +02:00
s = 1. / s ;
for ( int p = 0 ; p < it . nplanes ; p + + , + + it )
it . planes [ 0 ] * = s ;
# elif 1
// this is a shorter implementation of the above
2010-10-12 14:31:40 +02:00
// using built-in operations on Mat
2010-05-25 16:57:10 +02:00
double s = sum ( hist ) [ 0 ] ;
hist . convertTo ( hist , hist . type ( ) , 1. / s , 0 ) ;
# else
// and this is even shorter one
// (assuming that the histogram elements are non-negative)
normalize ( hist , hist , 1 , 0 , NORM_L1 ) ;
# endif
}
\ endcode
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
You can iterate through several matrices simultaneously as long as they have the same geometry
( dimensionality and all the dimension sizes are the same ) , which is useful for binary
and n - ary operations on such matrices . Just pass those matrices to cv : : MatNDIterator .
Then , during the iteration it . planes [ 0 ] , it . planes [ 1 ] , . . . will
be the slices of the corresponding matrices
*/
2010-10-12 14:31:40 +02:00
class CV_EXPORTS NAryMatIterator
2010-05-11 19:44:00 +02:00
{
public :
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-10-12 14:31:40 +02:00
NAryMatIterator ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor taking arbitrary number of n-dim matrices
2011-04-17 15:14:45 +02:00
NAryMatIterator ( const Mat * * arrays , uchar * * ptrs , int narrays = - 1 ) ;
//! the full constructor taking arbitrary number of n-dim matrices
2010-10-12 14:31:40 +02:00
NAryMatIterator ( const Mat * * arrays , Mat * planes , int narrays = - 1 ) ;
2010-05-25 16:57:10 +02:00
//! the separate iterator initialization method
2011-04-17 15:14:45 +02:00
void init ( const Mat * * arrays , Mat * planes , uchar * * ptrs , int narrays = - 1 ) ;
2010-05-11 19:44:00 +02:00
2012-05-28 13:22:43 +02:00
//! proceeds to the next plane of every iterated matrix
2010-10-12 14:31:40 +02:00
NAryMatIterator & operator + + ( ) ;
2010-05-25 16:57:10 +02:00
//! proceeds to the next plane of every iterated matrix (postfix increment operator)
2010-10-12 14:31:40 +02:00
NAryMatIterator operator + + ( int ) ;
2010-05-25 16:57:10 +02:00
//! the iterated arrays
2010-10-12 14:31:40 +02:00
const Mat * * arrays ;
2010-05-25 16:57:10 +02:00
//! the current planes
2010-10-12 14:31:40 +02:00
Mat * planes ;
2011-04-17 15:14:45 +02:00
//! data pointers
uchar * * ptrs ;
2010-10-12 14:31:40 +02:00
//! the number of arrays
int narrays ;
2011-04-17 15:14:45 +02:00
//! the number of hyper-planes that the iterator steps through
size_t nplanes ;
//! the size of each segment (in elements)
size_t size ;
2010-05-11 19:44:00 +02:00
protected :
2011-04-17 15:14:45 +02:00
int iterdepth ;
size_t idx ;
2010-05-11 19:44:00 +02:00
} ;
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
//typedef NAryMatIterator NAryMatNDIterator;
2010-05-11 19:44:00 +02:00
typedef void ( * ConvertData ) ( const void * from , void * to , int cn ) ;
typedef void ( * ConvertScaleData ) ( const void * from , void * to , int cn , double alpha , double beta ) ;
2010-05-25 16:57:10 +02:00
//! returns the function for converting pixels from one data type to another
2010-05-11 19:44:00 +02:00
CV_EXPORTS ConvertData getConvertElem ( int fromType , int toType ) ;
2010-05-25 16:57:10 +02:00
//! returns the function for converting pixels from one data type to another with the optional scaling
2010-05-11 19:44:00 +02:00
CV_EXPORTS ConvertScaleData getConvertScaleElem ( int fromType , int toType ) ;
2012-05-28 13:22:43 +02:00
2010-05-11 19:44:00 +02:00
/////////////////////////// multi-dimensional sparse matrix //////////////////////////
class SparseMatIterator ;
class SparseMatConstIterator ;
template < typename _Tp > class SparseMatIterator_ ;
template < typename _Tp > class SparseMatConstIterator_ ;
2010-05-25 16:57:10 +02:00
/*!
Sparse matrix class .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class represents multi - dimensional sparse numerical arrays . Such a sparse array can store elements
2010-10-12 14:31:40 +02:00
of any type that cv : : Mat is able to store . " Sparse " means that only non - zero elements
2010-05-25 16:57:10 +02:00
are stored ( though , as a result of some operations on a sparse matrix , some of its stored elements
can actually become 0. It ' s user responsibility to detect such elements and delete them using cv : : SparseMat : : erase ( ) .
The non - zero elements are stored in a hash table that grows when it ' s filled enough ,
so that the search time remains O ( 1 ) in average . Elements can be accessed using the following methods :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
< ol >
< li > Query operations : cv : : SparseMat : : ptr ( ) and the higher - level cv : : SparseMat : : ref ( ) ,
cv : : SparseMat : : value ( ) and cv : : SparseMat : : find , for example :
\ code
const int dims = 5 ;
int size [ ] = { 10 , 10 , 10 , 10 , 10 } ;
SparseMat sparse_mat ( dims , size , CV_32F ) ;
for ( int i = 0 ; i < 1000 ; i + + )
{
int idx [ dims ] ;
for ( int k = 0 ; k < dims ; k + + )
idx [ k ] = rand ( ) % sparse_mat . size ( k ) ;
sparse_mat . ref < float > ( idx ) + = 1.f ;
}
\ endcode
2012-05-28 13:22:43 +02:00
2010-10-12 14:31:40 +02:00
< li > Sparse matrix iterators . Like cv : : Mat iterators and unlike cv : : Mat iterators , the sparse matrix iterators are STL - style ,
2010-05-25 16:57:10 +02:00
that is , the iteration is done as following :
\ code
// prints elements of a sparse floating-point matrix and the sum of elements.
SparseMatConstIterator_ < float >
it = sparse_mat . begin < float > ( ) ,
it_end = sparse_mat . end < float > ( ) ;
double s = 0 ;
int dims = sparse_mat . dims ( ) ;
for ( ; it ! = it_end ; + + it )
{
// print element indices and the element value
const Node * n = it . node ( ) ;
printf ( " ( " )
for ( int i = 0 ; i < dims ; i + + )
printf ( " %3d%c " , n - > idx [ i ] , i < dims - 1 ? ' , ' : ' ) ' ) ;
2012-05-28 13:22:43 +02:00
printf ( " : %f \n " , * it ) ;
2010-05-25 16:57:10 +02:00
s + = * it ;
}
printf ( " Element sum is %g \n " , s ) ;
\ endcode
If you run this loop , you will notice that elements are enumerated
in no any logical order ( lexicographical etc . ) ,
they come in the same order as they stored in the hash table , i . e . semi - randomly .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
You may collect pointers to the nodes and sort them to get the proper ordering .
Note , however , that pointers to the nodes may become invalid when you add more
elements to the matrix ; this is because of possible buffer reallocation .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
< li > A combination of the above 2 methods when you need to process 2 or more sparse
matrices simultaneously , e . g . this is how you can compute unnormalized
cross - correlation of the 2 floating - point sparse matrices :
\ code
double crossCorr ( const SparseMat & a , const SparseMat & b )
{
const SparseMat * _a = & a , * _b = & b ;
// if b contains less elements than a,
// it's faster to iterate through b
if ( _a - > nzcount ( ) > _b - > nzcount ( ) )
std : : swap ( _a , _b ) ;
SparseMatConstIterator_ < float > it = _a - > begin < float > ( ) ,
it_end = _a - > end < float > ( ) ;
double ccorr = 0 ;
for ( ; it ! = it_end ; + + it )
{
// take the next element from the first matrix
float avalue = * it ;
const Node * anode = it . node ( ) ;
// and try to find element with the same index in the second matrix.
// since the hash value depends only on the element index,
// we reuse hashvalue stored in the node
float bvalue = _b - > value < float > ( anode - > idx , & anode - > hashval ) ;
ccorr + = avalue * bvalue ;
}
return ccorr ;
}
\ endcode
< / ol >
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS SparseMat
{
public :
typedef SparseMatIterator iterator ;
typedef SparseMatConstIterator const_iterator ;
2010-05-25 16:57:10 +02:00
//! the sparse matrix header
2010-05-11 19:44:00 +02:00
struct CV_EXPORTS Hdr
{
Hdr ( int _dims , const int * _sizes , int _type ) ;
void clear ( ) ;
int refcount ;
int dims ;
int valueOffset ;
size_t nodeSize ;
size_t nodeCount ;
size_t freeList ;
2013-02-24 17:14:01 +01:00
std : : vector < uchar > pool ;
std : : vector < size_t > hashtab ;
2010-05-11 19:44:00 +02:00
int size [ CV_MAX_DIM ] ;
} ;
2010-05-25 16:57:10 +02:00
//! sparse matrix node - element of a hash table
2010-05-11 19:44:00 +02:00
struct CV_EXPORTS Node
{
2010-05-25 16:57:10 +02:00
//! hash value
2010-05-11 19:44:00 +02:00
size_t hashval ;
2010-05-25 16:57:10 +02:00
//! index of the next node in the same hash table entry
2010-05-11 19:44:00 +02:00
size_t next ;
2010-05-25 16:57:10 +02:00
//! index of the matrix element
2010-05-11 19:44:00 +02:00
int idx [ CV_MAX_DIM ] ;
} ;
2010-05-25 16:57:10 +02:00
//! default constructor
2010-05-11 19:44:00 +02:00
SparseMat ( ) ;
2010-05-25 16:57:10 +02:00
//! creates matrix of the specified size and type
2010-05-11 19:44:00 +02:00
SparseMat ( int dims , const int * _sizes , int _type ) ;
2010-05-25 16:57:10 +02:00
//! copy constructor
2010-05-11 19:44:00 +02:00
SparseMat ( const SparseMat & m ) ;
2010-05-25 16:57:10 +02:00
//! converts dense 2d matrix to the sparse form
/*!
\ param m the input matrix
\ param try1d if true and m is a single - column matrix ( Nx1 ) ,
then the sparse matrix will be 1 - dimensional .
2012-05-28 13:22:43 +02:00
*/
2011-04-17 15:14:45 +02:00
explicit SparseMat ( const Mat & m ) ;
2010-05-25 16:57:10 +02:00
//! converts old-style sparse matrix to the new-style. All the data is copied
2010-05-11 19:44:00 +02:00
SparseMat ( const CvSparseMat * m ) ;
2010-05-25 16:57:10 +02:00
//! the destructor
2010-05-11 19:44:00 +02:00
~ SparseMat ( ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! assignment operator. This is O(1) operation, i.e. no data is copied
2010-05-11 19:44:00 +02:00
SparseMat & operator = ( const SparseMat & m ) ;
2010-10-12 14:31:40 +02:00
//! equivalent to the corresponding constructor
2010-05-11 19:44:00 +02:00
SparseMat & operator = ( const Mat & m ) ;
2010-05-25 16:57:10 +02:00
//! creates full copy of the matrix
2010-05-11 19:44:00 +02:00
SparseMat clone ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! copies all the data to the destination matrix. All the previous content of m is erased
2010-05-11 19:44:00 +02:00
void copyTo ( SparseMat & m ) const ;
2010-10-12 14:31:40 +02:00
//! converts sparse matrix to dense matrix.
2010-05-11 19:44:00 +02:00
void copyTo ( Mat & m ) const ;
2010-05-25 16:57:10 +02:00
//! multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type
2010-05-11 19:44:00 +02:00
void convertTo ( SparseMat & m , int rtype , double alpha = 1 ) const ;
2010-05-25 16:57:10 +02:00
//! converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.
/*!
\ param rtype The output matrix data type . When it is = - 1 , the output array will have the same data type as ( * this )
\ param alpha The scale factor
\ param beta The optional delta added to the scaled values before the conversion
*/
2010-05-11 19:44:00 +02:00
void convertTo ( Mat & m , int rtype , double alpha = 1 , double beta = 0 ) const ;
// not used now
void assignTo ( SparseMat & m , int type = - 1 ) const ;
2010-05-25 16:57:10 +02:00
//! reallocates sparse matrix.
/*!
2012-05-28 13:22:43 +02:00
If the matrix already had the proper size and type ,
2010-05-25 16:57:10 +02:00
it is simply cleared with clear ( ) , otherwise ,
the old matrix is released ( using release ( ) ) and the new one is allocated .
2012-05-28 13:22:43 +02:00
*/
2010-05-11 19:44:00 +02:00
void create ( int dims , const int * _sizes , int _type ) ;
2010-05-25 16:57:10 +02:00
//! sets all the sparse matrix elements to 0, which means clearing the hash table.
2010-05-11 19:44:00 +02:00
void clear ( ) ;
2010-05-25 16:57:10 +02:00
//! manually increments the reference counter to the header.
2010-05-11 19:44:00 +02:00
void addref ( ) ;
2010-05-25 16:57:10 +02:00
// decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated.
2010-05-11 19:44:00 +02:00
void release ( ) ;
2010-05-25 16:57:10 +02:00
//! converts sparse matrix to the old-style representation; all the elements are copied.
2010-05-11 19:44:00 +02:00
operator CvSparseMat * ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements)
2010-05-11 19:44:00 +02:00
size_t elemSize ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns elemSize()/channels()
2010-05-11 19:44:00 +02:00
size_t elemSize1 ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! returns type of sparse matrix elements
2010-05-11 19:44:00 +02:00
int type ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the depth of sparse matrix elements
2010-05-11 19:44:00 +02:00
int depth ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the number of channels
2010-05-11 19:44:00 +02:00
int channels ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! returns the array of sizes, or NULL if the matrix is not allocated
2010-05-11 19:44:00 +02:00
const int * size ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the size of i-th matrix dimension (or 0)
2010-05-11 19:44:00 +02:00
int size ( int i ) const ;
2010-05-25 16:57:10 +02:00
//! returns the matrix dimensionality
2010-05-11 19:44:00 +02:00
int dims ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the number of non-zero elements (=the number of hash table nodes)
2010-05-11 19:44:00 +02:00
size_t nzcount ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! computes the element hash value (1D case)
2010-05-11 19:44:00 +02:00
size_t hash ( int i0 ) const ;
2010-05-25 16:57:10 +02:00
//! computes the element hash value (2D case)
2010-05-11 19:44:00 +02:00
size_t hash ( int i0 , int i1 ) const ;
2010-05-25 16:57:10 +02:00
//! computes the element hash value (3D case)
2010-05-11 19:44:00 +02:00
size_t hash ( int i0 , int i1 , int i2 ) const ;
2010-05-25 16:57:10 +02:00
//! computes the element hash value (nD case)
2010-05-11 19:44:00 +02:00
size_t hash ( const int * idx ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//@{
/*!
2010-11-18 11:54:12 +01:00
specialized variants for 1 D , 2 D , 3 D cases and the generic_type one for n - D case .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
return pointer to the matrix element .
< ul >
< li > if the element is there ( it ' s non - zero ) , the pointer to it is returned
< li > if it ' s not there and createMissing = false , NULL pointer is returned
< li > if it ' s not there and createMissing = true , then the new element
is created and initialized with 0. Pointer to it is returned
< li > if the optional hashval pointer is not NULL , the element hash value is
not computed , but * hashval is taken instead .
< / ul >
*/
//! returns pointer to the specified element (1D case)
2010-05-11 19:44:00 +02:00
uchar * ptr ( int i0 , bool createMissing , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! returns pointer to the specified element (2D case)
2010-05-11 19:44:00 +02:00
uchar * ptr ( int i0 , int i1 , bool createMissing , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! returns pointer to the specified element (3D case)
2010-05-11 19:44:00 +02:00
uchar * ptr ( int i0 , int i1 , int i2 , bool createMissing , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! returns pointer to the specified element (nD case)
2010-05-11 19:44:00 +02:00
uchar * ptr ( const int * idx , bool createMissing , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//@}
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//@{
/*!
return read - write reference to the specified sparse matrix element .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
ref < _Tp > ( i0 , . . . [ , hashval ] ) is equivalent to * ( _Tp * ) ptr ( i0 , . . . , true [ , hashval ] ) .
The methods always return a valid reference .
2012-05-28 13:22:43 +02:00
If the element did not exist , it is created and initialiazed with 0.
2010-05-25 16:57:10 +02:00
*/
//! returns reference to the specified element (1D case)
2012-05-28 13:22:43 +02:00
template < typename _Tp > _Tp & ref ( int i0 , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! returns reference to the specified element (2D case)
2012-05-28 13:22:43 +02:00
template < typename _Tp > _Tp & ref ( int i0 , int i1 , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! returns reference to the specified element (3D case)
2010-05-11 19:44:00 +02:00
template < typename _Tp > _Tp & ref ( int i0 , int i1 , int i2 , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! returns reference to the specified element (nD case)
2010-05-11 19:44:00 +02:00
template < typename _Tp > _Tp & ref ( const int * idx , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//@}
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//@{
/*!
return value of the specified sparse matrix element .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
value < _Tp > ( i0 , . . . [ , hashval ] ) is equivalent
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
{ const _Tp * p = find < _Tp > ( i0 , . . . [ , hashval ] ) ; return p ? * p : _Tp ( ) ; }
\ endcode
That is , if the element did not exist , the methods return 0.
*/
//! returns value of the specified element (1D case)
template < typename _Tp > _Tp value ( int i0 , size_t * hashval = 0 ) const ;
//! returns value of the specified element (2D case)
template < typename _Tp > _Tp value ( int i0 , int i1 , size_t * hashval = 0 ) const ;
//! returns value of the specified element (3D case)
template < typename _Tp > _Tp value ( int i0 , int i1 , int i2 , size_t * hashval = 0 ) const ;
//! returns value of the specified element (nD case)
2010-05-11 19:44:00 +02:00
template < typename _Tp > _Tp value ( const int * idx , size_t * hashval = 0 ) const ;
2010-05-25 16:57:10 +02:00
//@}
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//@{
/*!
Return pointer to the specified sparse matrix element if it exists
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
find < _Tp > ( i0 , . . . [ , hashval ] ) is equivalent to ( _const Tp * ) ptr ( i0 , . . . false [ , hashval ] ) .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
If the specified element does not exist , the methods return NULL .
*/
//! returns pointer to the specified element (1D case)
template < typename _Tp > const _Tp * find ( int i0 , size_t * hashval = 0 ) const ;
//! returns pointer to the specified element (2D case)
template < typename _Tp > const _Tp * find ( int i0 , int i1 , size_t * hashval = 0 ) const ;
//! returns pointer to the specified element (3D case)
template < typename _Tp > const _Tp * find ( int i0 , int i1 , int i2 , size_t * hashval = 0 ) const ;
//! returns pointer to the specified element (nD case)
2010-05-11 19:44:00 +02:00
template < typename _Tp > const _Tp * find ( const int * idx , size_t * hashval = 0 ) const ;
2010-05-25 16:57:10 +02:00
//! erases the specified element (2D case)
2010-05-11 19:44:00 +02:00
void erase ( int i0 , int i1 , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! erases the specified element (3D case)
2010-05-11 19:44:00 +02:00
void erase ( int i0 , int i1 , int i2 , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! erases the specified element (nD case)
2010-05-11 19:44:00 +02:00
void erase ( const int * idx , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//@{
/*!
return the sparse matrix iterator pointing to the first sparse matrix element
2012-05-28 13:22:43 +02:00
*/
2010-05-25 16:57:10 +02:00
//! returns the sparse matrix iterator at the matrix beginning
2010-05-11 19:44:00 +02:00
SparseMatIterator begin ( ) ;
2010-05-25 16:57:10 +02:00
//! returns the sparse matrix iterator at the matrix beginning
template < typename _Tp > SparseMatIterator_ < _Tp > begin ( ) ;
//! returns the read-only sparse matrix iterator at the matrix beginning
2010-05-11 19:44:00 +02:00
SparseMatConstIterator begin ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the read-only sparse matrix iterator at the matrix beginning
template < typename _Tp > SparseMatConstIterator_ < _Tp > begin ( ) const ;
//@}
/*!
return the sparse matrix iterator pointing to the element following the last sparse matrix element
2012-05-28 13:22:43 +02:00
*/
2010-05-25 16:57:10 +02:00
//! returns the sparse matrix iterator at the matrix end
2010-05-11 19:44:00 +02:00
SparseMatIterator end ( ) ;
2010-05-25 16:57:10 +02:00
//! returns the read-only sparse matrix iterator at the matrix end
2010-05-11 19:44:00 +02:00
SparseMatConstIterator end ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the typed sparse matrix iterator at the matrix end
2010-05-11 19:44:00 +02:00
template < typename _Tp > SparseMatIterator_ < _Tp > end ( ) ;
2010-05-25 16:57:10 +02:00
//! returns the typed read-only sparse matrix iterator at the matrix end
2010-05-11 19:44:00 +02:00
template < typename _Tp > SparseMatConstIterator_ < _Tp > end ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the value stored in the sparse martix node
2010-05-11 19:44:00 +02:00
template < typename _Tp > _Tp & value ( Node * n ) ;
2010-05-25 16:57:10 +02:00
//! returns the value stored in the sparse martix node
2010-05-11 19:44:00 +02:00
template < typename _Tp > const _Tp & value ( const Node * n ) const ;
2012-05-28 13:22:43 +02:00
2010-05-11 19:44:00 +02:00
////////////// some internal-use methods ///////////////
Node * node ( size_t nidx ) ;
const Node * node ( size_t nidx ) const ;
uchar * newNode ( const int * idx , size_t hashval ) ;
void removeNode ( size_t hidx , size_t nidx , size_t previdx ) ;
void resizeHashTab ( size_t newsize ) ;
enum { MAGIC_VAL = 0x42FD0000 , MAX_DIM = CV_MAX_DIM , HASH_SCALE = 0x5bd1e995 , HASH_BIT = 0x80000000 } ;
int flags ;
Hdr * hdr ;
} ;
2010-05-25 16:57:10 +02:00
//! finds global minimum and maximum sparse array elements and returns their values and their locations
2010-05-11 19:44:00 +02:00
CV_EXPORTS void minMaxLoc ( const SparseMat & a , double * minVal ,
double * maxVal , int * minIdx = 0 , int * maxIdx = 0 ) ;
2010-05-25 16:57:10 +02:00
//! computes norm of a sparse matrix
2010-05-11 19:44:00 +02:00
CV_EXPORTS double norm ( const SparseMat & src , int normType ) ;
2012-05-28 13:22:43 +02:00
//! scales and shifts array elements so that either the specified norm (alpha) or the minimum (alpha) and maximum (beta) array values get the specified values
2010-05-11 19:44:00 +02:00
CV_EXPORTS void normalize ( const SparseMat & src , SparseMat & dst , double alpha , int normType ) ;
2010-05-25 16:57:10 +02:00
/*!
Read - Only Sparse Matrix Iterator .
Here is how to use the iterator to compute the sum of floating - point sparse matrix elements :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
SparseMatConstIterator it = m . begin ( ) , it_end = m . end ( ) ;
double s = 0 ;
CV_Assert ( m . type ( ) = = CV_32F ) ;
for ( ; it ! = it_end ; + + it )
s + = it . value < float > ( ) ;
\ endcode
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS SparseMatConstIterator
{
public :
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-05-11 19:44:00 +02:00
SparseMatConstIterator ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor setting the iterator to the first sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator ( const SparseMat * _m ) ;
2010-05-25 16:57:10 +02:00
//! the copy constructor
2010-05-11 19:44:00 +02:00
SparseMatConstIterator ( const SparseMatConstIterator & it ) ;
2010-05-25 16:57:10 +02:00
//! the assignment operator
2010-05-11 19:44:00 +02:00
SparseMatConstIterator & operator = ( const SparseMatConstIterator & it ) ;
2010-05-25 16:57:10 +02:00
//! template method returning the current matrix element
2010-05-11 19:44:00 +02:00
template < typename _Tp > const _Tp & value ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the current node of the sparse matrix. it.node->idx is the current element index
2010-05-11 19:44:00 +02:00
const SparseMat : : Node * node ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! moves iterator to the previous element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator & operator - - ( ) ;
2010-05-25 16:57:10 +02:00
//! moves iterator to the previous element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator operator - - ( int ) ;
2010-05-25 16:57:10 +02:00
//! moves iterator to the next element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator & operator + + ( ) ;
2010-05-25 16:57:10 +02:00
//! moves iterator to the next element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator operator + + ( int ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! moves iterator to the element after the last element
2010-05-11 19:44:00 +02:00
void seekEnd ( ) ;
const SparseMat * m ;
size_t hashidx ;
uchar * ptr ;
} ;
2010-05-25 16:57:10 +02:00
/*!
Read - write Sparse Matrix Iterator
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class is similar to cv : : SparseMatConstIterator ,
but can be used for in - place modification of the matrix elements .
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator
{
public :
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-05-11 19:44:00 +02:00
SparseMatIterator ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor setting the iterator to the first sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatIterator ( SparseMat * _m ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor setting the iterator to the specified sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatIterator ( SparseMat * _m , const int * idx ) ;
2010-05-25 16:57:10 +02:00
//! the copy constructor
2010-05-11 19:44:00 +02:00
SparseMatIterator ( const SparseMatIterator & it ) ;
2010-05-25 16:57:10 +02:00
//! the assignment operator
2010-05-11 19:44:00 +02:00
SparseMatIterator & operator = ( const SparseMatIterator & it ) ;
2010-05-25 16:57:10 +02:00
//! returns read-write reference to the current sparse matrix element
2010-05-11 19:44:00 +02:00
template < typename _Tp > _Tp & value ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns pointer to the current sparse matrix node. it.node->idx is the index of the current element (do not modify it!)
2010-05-11 19:44:00 +02:00
SparseMat : : Node * node ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! moves iterator to the next element
2010-05-11 19:44:00 +02:00
SparseMatIterator & operator + + ( ) ;
2010-05-25 16:57:10 +02:00
//! moves iterator to the next element
2010-05-11 19:44:00 +02:00
SparseMatIterator operator + + ( int ) ;
} ;
2010-05-25 16:57:10 +02:00
/*!
The Template Sparse Matrix class derived from cv : : SparseMat
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class provides slightly more convenient operations for accessing elements .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
SparseMat m ;
. . .
SparseMat_ < int > m_ = ( SparseMat_ < int > & ) m ;
m_ . ref ( 1 ) + + ; // equivalent to m.ref<int>(1)++;
m_ . ref ( 2 ) + = m_ ( 3 ) ; // equivalent to m.ref<int>(2) += m.value<int>(3);
\ endcode
2012-05-28 13:22:43 +02:00
*/
2010-05-11 19:44:00 +02:00
template < typename _Tp > class CV_EXPORTS SparseMat_ : public SparseMat
{
public :
typedef SparseMatIterator_ < _Tp > iterator ;
typedef SparseMatConstIterator_ < _Tp > const_iterator ;
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-05-11 19:44:00 +02:00
SparseMat_ ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor equivelent to SparseMat(dims, _sizes, DataType<_Tp>::type)
2010-05-11 19:44:00 +02:00
SparseMat_ ( int dims , const int * _sizes ) ;
2010-05-25 16:57:10 +02:00
//! the copy constructor. If DataType<_Tp>.type != m.type(), the m elements are converted
2010-05-11 19:44:00 +02:00
SparseMat_ ( const SparseMat & m ) ;
2010-05-25 16:57:10 +02:00
//! the copy constructor. This is O(1) operation - no data is copied
2010-05-11 19:44:00 +02:00
SparseMat_ ( const SparseMat_ & m ) ;
2010-10-12 14:31:40 +02:00
//! converts dense matrix to the sparse form
2010-05-11 19:44:00 +02:00
SparseMat_ ( const Mat & m ) ;
2010-05-25 16:57:10 +02:00
//! converts the old-style sparse matrix to the C++ class. All the elements are copied
2010-05-11 19:44:00 +02:00
SparseMat_ ( const CvSparseMat * m ) ;
2010-05-25 16:57:10 +02:00
//! the assignment operator. If DataType<_Tp>.type != m.type(), the m elements are converted
2010-05-11 19:44:00 +02:00
SparseMat_ & operator = ( const SparseMat & m ) ;
2012-05-28 13:22:43 +02:00
//! the assignment operator. This is O(1) operation - no data is copied
2010-05-11 19:44:00 +02:00
SparseMat_ & operator = ( const SparseMat_ & m ) ;
2010-10-12 14:31:40 +02:00
//! converts dense matrix to the sparse form
2010-05-11 19:44:00 +02:00
SparseMat_ & operator = ( const Mat & m ) ;
2010-05-25 16:57:10 +02:00
//! makes full copy of the matrix. All the elements are duplicated
2010-05-11 19:44:00 +02:00
SparseMat_ clone ( ) const ;
2010-05-25 16:57:10 +02:00
//! equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type)
2010-05-11 19:44:00 +02:00
void create ( int dims , const int * _sizes ) ;
2010-05-25 16:57:10 +02:00
//! converts sparse matrix to the old-style CvSparseMat. All the elements are copied
2010-05-11 19:44:00 +02:00
operator CvSparseMat * ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns type of the matrix elements
2010-05-11 19:44:00 +02:00
int type ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns depth of the matrix elements
2010-05-11 19:44:00 +02:00
int depth ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the number of channels in each matrix element
2010-05-11 19:44:00 +02:00
int channels ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! equivalent to SparseMat::ref<_Tp>(i0, hashval)
2010-05-11 19:44:00 +02:00
_Tp & ref ( int i0 , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! equivalent to SparseMat::ref<_Tp>(i0, i1, hashval)
2010-05-11 19:44:00 +02:00
_Tp & ref ( int i0 , int i1 , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval)
2010-05-11 19:44:00 +02:00
_Tp & ref ( int i0 , int i1 , int i2 , size_t * hashval = 0 ) ;
2010-05-25 16:57:10 +02:00
//! equivalent to SparseMat::ref<_Tp>(idx, hashval)
2010-05-11 19:44:00 +02:00
_Tp & ref ( const int * idx , size_t * hashval = 0 ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! equivalent to SparseMat::value<_Tp>(i0, hashval)
_Tp operator ( ) ( int i0 , size_t * hashval = 0 ) const ;
//! equivalent to SparseMat::value<_Tp>(i0, i1, hashval)
_Tp operator ( ) ( int i0 , int i1 , size_t * hashval = 0 ) const ;
//! equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval)
_Tp operator ( ) ( int i0 , int i1 , int i2 , size_t * hashval = 0 ) const ;
//! equivalent to SparseMat::value<_Tp>(idx, hashval)
2010-05-11 19:44:00 +02:00
_Tp operator ( ) ( const int * idx , size_t * hashval = 0 ) const ;
2010-05-25 16:57:10 +02:00
//! returns sparse matrix iterator pointing to the first sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatIterator_ < _Tp > begin ( ) ;
2010-05-25 16:57:10 +02:00
//! returns read-only sparse matrix iterator pointing to the first sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator_ < _Tp > begin ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns sparse matrix iterator pointing to the element following the last sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatIterator_ < _Tp > end ( ) ;
2010-05-25 16:57:10 +02:00
//! returns read-only sparse matrix iterator pointing to the element following the last sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator_ < _Tp > end ( ) const ;
} ;
2010-05-25 16:57:10 +02:00
/*!
Template Read - Only Sparse Matrix Iterator Class .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
This is the derived from SparseMatConstIterator class that
introduces more convenient operator * ( ) for accessing the current element .
*/
2010-05-11 19:44:00 +02:00
template < typename _Tp > class CV_EXPORTS SparseMatConstIterator_ : public SparseMatConstIterator
{
public :
typedef std : : forward_iterator_tag iterator_category ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-05-11 19:44:00 +02:00
SparseMatConstIterator_ ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor setting the iterator to the first sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator_ ( const SparseMat_ < _Tp > * _m ) ;
2010-05-25 16:57:10 +02:00
//! the copy constructor
2010-05-11 19:44:00 +02:00
SparseMatConstIterator_ ( const SparseMatConstIterator_ & it ) ;
2010-05-25 16:57:10 +02:00
//! the assignment operator
2010-05-11 19:44:00 +02:00
SparseMatConstIterator_ & operator = ( const SparseMatConstIterator_ & it ) ;
2010-05-25 16:57:10 +02:00
//! the element access operator
2010-05-11 19:44:00 +02:00
const _Tp & operator * ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! moves iterator to the next element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator_ & operator + + ( ) ;
2010-05-25 16:57:10 +02:00
//! moves iterator to the next element
2010-05-11 19:44:00 +02:00
SparseMatConstIterator_ operator + + ( int ) ;
} ;
2010-05-25 16:57:10 +02:00
/*!
Template Read - Write Sparse Matrix Iterator Class .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
This is the derived from cv : : SparseMatConstIterator_ class that
introduces more convenient operator * ( ) for accessing the current element .
*/
2010-05-11 19:44:00 +02:00
template < typename _Tp > class CV_EXPORTS SparseMatIterator_ : public SparseMatConstIterator_ < _Tp >
{
public :
typedef std : : forward_iterator_tag iterator_category ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-05-11 19:44:00 +02:00
SparseMatIterator_ ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor setting the iterator to the first sparse matrix element
2010-05-11 19:44:00 +02:00
SparseMatIterator_ ( SparseMat_ < _Tp > * _m ) ;
2010-05-25 16:57:10 +02:00
//! the copy constructor
2010-05-11 19:44:00 +02:00
SparseMatIterator_ ( const SparseMatIterator_ & it ) ;
2012-05-28 13:22:43 +02:00
//! the assignment operator
2010-05-11 19:44:00 +02:00
SparseMatIterator_ & operator = ( const SparseMatIterator_ & it ) ;
2010-05-25 16:57:10 +02:00
//! returns the reference to the current element
2010-05-11 19:44:00 +02:00
_Tp & operator * ( ) const ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! moves the iterator to the next element
2010-05-11 19:44:00 +02:00
SparseMatIterator_ & operator + + ( ) ;
2010-05-25 16:57:10 +02:00
//! moves the iterator to the next element
2010-05-11 19:44:00 +02:00
SparseMatIterator_ operator + + ( int ) ;
} ;
//////////////////// Fast Nearest-Neighbor Search Structure ////////////////////
2010-05-25 16:57:10 +02:00
/*!
Fast Nearest Neighbor Search Class .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class implements D . Lowe BBF ( Best - Bin - First ) algorithm for the last
approximate ( or accurate ) nearest neighbor search in multi - dimensional spaces .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
First , a set of vectors is passed to KDTree : : KDTree ( ) constructor
or KDTree : : build ( ) method , where it is reordered .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
Then arbitrary vectors can be passed to KDTree : : findNearest ( ) methods , which
find the K nearest neighbors among the vectors from the initial set .
The user can balance between the speed and accuracy of the search by varying Emax
parameter , which is the number of leaves that the algorithm checks .
The larger parameter values yield more accurate results at the expense of lower processing speed .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
KDTree T ( points , false ) ;
const int K = 3 , Emax = INT_MAX ;
int idx [ K ] ;
float dist [ K ] ;
T . findNearest ( query_vec , K , Emax , idx , 0 , dist ) ;
CV_Assert ( dist [ 0 ] < = dist [ 1 ] & & dist [ 1 ] < = dist [ 2 ] ) ;
\ endcode
2012-05-28 13:22:43 +02:00
*/
2010-10-27 20:26:39 +02:00
class CV_EXPORTS_W KDTree
2010-05-11 19:44:00 +02:00
{
public :
2010-05-25 16:57:10 +02:00
/*!
The node of the search tree .
2012-05-28 13:22:43 +02:00
*/
2010-05-11 19:44:00 +02:00
struct Node
{
Node ( ) : idx ( - 1 ) , left ( - 1 ) , right ( - 1 ) , boundary ( 0.f ) { }
Node ( int _idx , int _left , int _right , float _boundary )
: idx ( _idx ) , left ( _left ) , right ( _right ) , boundary ( _boundary ) { }
2010-05-25 16:57:10 +02:00
//! split dimension; >=0 for nodes (dim), < 0 for leaves (index of the point)
int idx ;
//! node indices of the left and the right branches
int left , right ;
//! go to the left if query_vec[node.idx]<=node.boundary, otherwise go to the right
float boundary ;
2010-05-11 19:44:00 +02:00
} ;
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-10-27 20:26:39 +02:00
CV_WRAP KDTree ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor that builds the search tree
2011-06-06 16:51:27 +02:00
CV_WRAP KDTree ( InputArray points , bool copyAndReorderPoints = false ) ;
2010-11-02 18:58:22 +01:00
//! the full constructor that builds the search tree
2011-06-06 16:51:27 +02:00
CV_WRAP KDTree ( InputArray points , InputArray _labels ,
2011-04-17 15:14:45 +02:00
bool copyAndReorderPoints = false ) ;
2010-05-25 16:57:10 +02:00
//! builds the search tree
2011-06-06 16:51:27 +02:00
CV_WRAP void build ( InputArray points , bool copyAndReorderPoints = false ) ;
2010-11-02 18:58:22 +01:00
//! builds the search tree
2011-06-06 16:51:27 +02:00
CV_WRAP void build ( InputArray points , InputArray labels ,
2011-04-17 15:14:45 +02:00
bool copyAndReorderPoints = false ) ;
2010-05-25 16:57:10 +02:00
//! finds the K nearest neighbors of "vec" while looking at Emax (at most) leaves
2011-06-06 16:51:27 +02:00
CV_WRAP int findNearest ( InputArray vec , int K , int Emax ,
2011-04-17 15:14:45 +02:00
OutputArray neighborsIdx ,
2011-06-08 08:55:04 +02:00
OutputArray neighbors = noArray ( ) ,
OutputArray dist = noArray ( ) ,
OutputArray labels = noArray ( ) ) const ;
2012-05-28 13:22:43 +02:00
//! finds all the points from the initial set that belong to the specified box
2011-06-06 16:51:27 +02:00
CV_WRAP void findOrthoRange ( InputArray minBounds ,
InputArray maxBounds ,
2011-04-17 15:14:45 +02:00
OutputArray neighborsIdx ,
2011-06-08 08:55:04 +02:00
OutputArray neighbors = noArray ( ) ,
OutputArray labels = noArray ( ) ) const ;
2010-05-25 16:57:10 +02:00
//! returns vectors with the specified indices
2011-06-06 16:51:27 +02:00
CV_WRAP void getPoints ( InputArray idx , OutputArray pts ,
2011-06-08 08:55:04 +02:00
OutputArray labels = noArray ( ) ) const ;
2010-05-25 16:57:10 +02:00
//! return a vector with the specified index
2010-11-02 18:58:22 +01:00
const float * getPoint ( int ptidx , int * label = 0 ) const ;
2010-05-25 16:57:10 +02:00
//! returns the search space dimensionality
2010-10-27 20:26:39 +02:00
CV_WRAP int dims ( ) const ;
2010-05-11 19:44:00 +02:00
2013-02-24 17:14:01 +01:00
std : : vector < Node > nodes ; //!< all the tree nodes
2010-10-27 20:26:39 +02:00
CV_PROP Mat points ; //!< all the points. It can be a reordered copy of the input vector set or the original vector set.
2013-02-24 17:14:01 +01:00
CV_PROP std : : vector < int > labels ; //!< the parallel array of labels.
2010-10-27 20:26:39 +02:00
CV_PROP int maxDepth ; //!< maximum depth of the search tree. Do not modify it
CV_PROP_RW int normType ; //!< type of the distance (cv::NORM_L1 or cv::NORM_L2) used for search. Initially set to cv::NORM_L2, but you can modify it
2010-05-11 19:44:00 +02:00
} ;
//////////////////////////////////////// XML & YAML I/O ////////////////////////////////////
class CV_EXPORTS FileNode ;
2010-05-25 16:57:10 +02:00
/*!
XML / YAML File Storage Class .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class describes an object associated with XML or YAML file .
It can be used to store data to such a file or read and decode the data .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The storage is organized as a tree of nested sequences ( or lists ) and mappings .
Sequence is a heterogenious array , which elements are accessed by indices or sequentially using an iterator .
Mapping is analogue of std : : map or C structure , which elements are accessed by names .
The most top level structure is a mapping .
2012-05-28 13:22:43 +02:00
Leaves of the file storage tree are integers , floating - point numbers and text strings .
2010-05-25 16:57:10 +02:00
For example , the following code :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
// open file storage for writing. Type of the file is determined from the extension
FileStorage fs ( " test.yml " , FileStorage : : WRITE ) ;
fs < < " test_int " < < 5 < < " test_real " < < 3.1 < < " test_string " < < " ABCDEFGH " ;
fs < < " test_mat " < < Mat : : eye ( 3 , 3 , CV_32F ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
fs < < " test_list " < < " [ " < < 0.0000000000001 < < 2 < < CV_PI < < - 3435345 < < " 2-502 2-029 3egegeg " < <
" {: " < < " month " < < 12 < < " day " < < 31 < < " year " < < 1969 < < " } " < < " ] " ;
fs < < " test_map " < < " { " < < " x " < < 1 < < " y " < < 2 < < " width " < < 100 < < " height " < < 200 < < " lbp " < < " [: " ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
const uchar arr [ ] = { 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 } ;
fs . writeRaw ( " u " , arr , ( int ) ( sizeof ( arr ) / sizeof ( arr [ 0 ] ) ) ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
fs < < " ] " < < " } " ;
\ endcode
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
will produce the following file :
\ verbatim
% YAML : 1.0
test_int : 5
test_real : 3.1000000000000001e+00
test_string : ABCDEFGH
test_mat : ! ! opencv - matrix
rows : 3
cols : 3
dt : f
data : [ 1. , 0. , 0. , 0. , 1. , 0. , 0. , 0. , 1. ]
test_list :
- 1.0000000000000000e-13
- 2
- 3.1415926535897931e+00
- - 3435345
- " 2-502 2-029 3egegeg "
- { month : 12 , day : 31 , year : 1969 }
test_map :
x : 1
y : 2
width : 100
height : 200
lbp : [ 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 ]
\ endverbatim
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
and to read the file above , the following code can be used :
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
\ code
// open file storage for reading.
// Type of the file is determined from the content, not the extension
FileStorage fs ( " test.yml " , FileStorage : : READ ) ;
int test_int = ( int ) fs [ " test_int " ] ;
double test_real = ( double ) fs [ " test_real " ] ;
2013-03-22 17:37:49 +01:00
String test_string = ( String ) fs [ " test_string " ] ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
Mat M ;
fs [ " test_mat " ] > > M ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
FileNode tl = fs [ " test_list " ] ;
CV_Assert ( tl . type ( ) = = FileNode : : SEQ & & tl . size ( ) = = 6 ) ;
double tl0 = ( double ) tl [ 0 ] ;
int tl1 = ( int ) tl [ 1 ] ;
double tl2 = ( double ) tl [ 2 ] ;
int tl3 = ( int ) tl [ 3 ] ;
2013-03-22 17:37:49 +01:00
String tl4 = ( String ) tl [ 4 ] ;
2010-05-25 16:57:10 +02:00
CV_Assert ( tl [ 5 ] . type ( ) = = FileNode : : MAP & & tl [ 5 ] . size ( ) = = 3 ) ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
int month = ( int ) tl [ 5 ] [ " month " ] ;
int day = ( int ) tl [ 5 ] [ " day " ] ;
int year = ( int ) tl [ 5 ] [ " year " ] ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
FileNode tm = fs [ " test_map " ] ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
int x = ( int ) tm [ " x " ] ;
int y = ( int ) tm [ " y " ] ;
int width = ( int ) tm [ " width " ] ;
int height = ( int ) tm [ " height " ] ;
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
int lbp_val = 0 ;
FileNodeIterator it = tm [ " lbp " ] . begin ( ) ;
for ( int k = 0 ; k < 8 ; k + + , + + it )
lbp_val | = ( ( int ) * it ) < < k ;
\ endcode
*/
2010-10-27 20:26:39 +02:00
class CV_EXPORTS_W FileStorage
2010-05-11 19:44:00 +02:00
{
public :
2010-05-25 16:57:10 +02:00
//! file storage mode
enum
{
READ = 0 , //! read mode
WRITE = 1 , //! write mode
2012-05-28 17:38:58 +02:00
APPEND = 2 , //! append mode
MEMORY = 4 ,
FORMAT_MASK = ( 7 < < 3 ) ,
FORMAT_AUTO = 0 ,
FORMAT_XML = ( 1 < < 3 ) ,
FORMAT_YAML = ( 2 < < 3 )
2010-05-25 16:57:10 +02:00
} ;
enum
{
2012-05-28 13:22:43 +02:00
UNDEFINED = 0 ,
2010-05-25 16:57:10 +02:00
VALUE_EXPECTED = 1 ,
NAME_EXPECTED = 2 ,
INSIDE_MAP = 4
} ;
//! the default constructor
2010-10-27 20:26:39 +02:00
CV_WRAP FileStorage ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor that opens file storage for reading or writing
2013-03-22 17:37:49 +01:00
CV_WRAP FileStorage ( const String & source , int flags , const String & encoding = String ( ) ) ;
2012-05-28 13:22:43 +02:00
//! the constructor that takes pointer to the C FileStorage structure
2010-05-11 19:44:00 +02:00
FileStorage ( CvFileStorage * fs ) ;
2010-05-25 16:57:10 +02:00
//! the destructor. calls release()
2010-05-11 19:44:00 +02:00
virtual ~ FileStorage ( ) ;
2010-05-25 16:57:10 +02:00
//! opens file storage for reading or writing. The previous storage is closed with release()
2013-03-22 17:37:49 +01:00
CV_WRAP virtual bool open ( const String & filename , int flags , const String & encoding = String ( ) ) ;
2010-05-25 16:57:10 +02:00
//! returns true if the object is associated with currently opened file.
2010-10-27 20:26:39 +02:00
CV_WRAP virtual bool isOpened ( ) const ;
2010-05-25 16:57:10 +02:00
//! closes the file and releases all the memory buffers
2012-05-30 13:29:22 +02:00
CV_WRAP virtual void release ( ) ;
2012-06-07 19:21:29 +02:00
//! closes the file, releases all the memory buffers and returns the text string
2013-03-22 17:37:49 +01:00
CV_WRAP virtual String releaseAndGetString ( ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! returns the first element of the top-level mapping
2010-10-27 20:26:39 +02:00
CV_WRAP FileNode getFirstTopLevelNode ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the top-level mapping. YAML supports multiple streams
2010-10-27 20:26:39 +02:00
CV_WRAP FileNode root ( int streamidx = 0 ) const ;
2010-05-25 16:57:10 +02:00
//! returns the specified element of the top-level mapping
2013-03-22 17:37:49 +01:00
FileNode operator [ ] ( const String & nodename ) const ;
2010-05-25 16:57:10 +02:00
//! returns the specified element of the top-level mapping
2010-10-27 20:26:39 +02:00
CV_WRAP FileNode operator [ ] ( const char * nodename ) const ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! returns pointer to the underlying C FileStorage structure
2010-05-11 19:44:00 +02:00
CvFileStorage * operator * ( ) { return fs ; }
2010-05-25 16:57:10 +02:00
//! returns pointer to the underlying C FileStorage structure
2010-05-11 19:44:00 +02:00
const CvFileStorage * operator * ( ) const { return fs ; }
2010-05-25 16:57:10 +02:00
//! writes one or more numbers of the specified format to the currently written structure
2013-03-22 17:37:49 +01:00
void writeRaw ( const String & fmt , const uchar * vec , size_t len ) ;
2010-05-25 16:57:10 +02:00
//! writes the registered C structure (CvMat, CvMatND, CvSeq). See cvWrite()
2013-03-22 17:37:49 +01:00
void writeObj ( const String & name , const void * obj ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! returns the normalized object name for the specified file name
2013-03-22 17:37:49 +01:00
static String getDefaultObjectName ( const String & filename ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
Ptr < CvFileStorage > fs ; //!< the underlying C FileStorage structure
2013-03-22 17:37:49 +01:00
String elname ; //!< the currently written element
2013-02-24 17:14:01 +01:00
std : : vector < char > structs ; //!< the stack of written structures
2010-05-25 16:57:10 +02:00
int state ; //!< the writer state
2010-05-11 19:44:00 +02:00
} ;
class CV_EXPORTS FileNodeIterator ;
2010-05-25 16:57:10 +02:00
/*!
File Storage Node class
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The node is used to store each and every element of the file storage opened for reading -
from the primitive objects , such as numbers and text strings , to the complex nodes :
sequences , mappings and the registered objects .
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
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 .
*/
2010-11-02 18:58:22 +01:00
class CV_EXPORTS_W_SIMPLE FileNode
2010-05-11 19:44:00 +02:00
{
public :
2010-05-25 16:57:10 +02:00
//! type of the file storage node
enum
{
NONE = 0 , //!< empty node
INT = 1 , //!< an integer
REAL = 2 , //!< floating-point number
FLOAT = REAL , //!< synonym or REAL
STR = 3 , //!< text string in UTF-8 encoding
STRING = STR , //!< synonym for STR
2012-05-28 13:22:43 +02:00
REF = 4 , //!< integer of size size_t. Typically used for storing complex dynamic structures where some elements reference the others
2010-05-25 16:57:10 +02:00
SEQ = 5 , //!< sequence
MAP = 6 , //!< mapping
TYPE_MASK = 7 ,
FLOW = 8 , //!< compact representation of a sequence or mapping. Used only by YAML writer
USER = 16 , //!< a registered object (e.g. a matrix)
EMPTY = 32 , //!< empty structure (sequence or mapping)
NAMED = 64 //!< the node has a name (i.e. it is element of a mapping)
} ;
//! the default constructor
2010-10-27 20:26:39 +02:00
CV_WRAP FileNode ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor wrapping CvFileNode structure.
2010-05-11 19:44:00 +02:00
FileNode ( const CvFileStorage * fs , const CvFileNode * node ) ;
2010-05-25 16:57:10 +02:00
//! the copy constructor
2010-05-11 19:44:00 +02:00
FileNode ( const FileNode & node ) ;
2010-05-25 16:57:10 +02:00
//! returns element of a mapping node
2013-03-22 17:37:49 +01:00
FileNode operator [ ] ( const String & nodename ) const ;
2010-05-25 16:57:10 +02:00
//! returns element of a mapping node
2010-10-27 20:26:39 +02:00
CV_WRAP FileNode operator [ ] ( const char * nodename ) const ;
2010-05-25 16:57:10 +02:00
//! returns element of a sequence node
2010-10-27 20:26:39 +02:00
CV_WRAP FileNode operator [ ] ( int i ) const ;
2010-05-25 16:57:10 +02:00
//! returns type of the node
2010-10-27 20:26:39 +02:00
CV_WRAP int type ( ) const ;
2010-05-25 16:57:10 +02:00
2012-05-28 13:22:43 +02:00
//! returns true if the node is empty
2010-10-27 20:26:39 +02:00
CV_WRAP bool empty ( ) const ;
2012-05-28 13:22:43 +02:00
//! returns true if the node is a "none" object
2010-10-27 20:26:39 +02:00
CV_WRAP bool isNone ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns true if the node is a sequence
2010-10-27 20:26:39 +02:00
CV_WRAP bool isSeq ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns true if the node is a mapping
2010-10-27 20:26:39 +02:00
CV_WRAP bool isMap ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns true if the node is an integer
2010-10-27 20:26:39 +02:00
CV_WRAP bool isInt ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns true if the node is a floating-point number
2010-10-27 20:26:39 +02:00
CV_WRAP bool isReal ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns true if the node is a text string
2010-10-27 20:26:39 +02:00
CV_WRAP bool isString ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns true if the node has a name
2010-10-27 20:26:39 +02:00
CV_WRAP bool isNamed ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the node name or an empty string if the node is nameless
2013-03-22 17:37:49 +01:00
CV_WRAP String name ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise.
2010-10-27 20:26:39 +02:00
CV_WRAP size_t size ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the node content as an integer. If the node stores floating-point number, it is rounded.
2010-11-02 18:58:22 +01:00
operator int ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the node content as float
2010-11-02 18:58:22 +01:00
operator float ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the node content as double
2010-11-02 18:58:22 +01:00
operator double ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns the node content as text string
2013-03-20 10:00:04 +01:00
operator String ( ) const ;
# ifndef OPENCV_NOSTL
2013-02-24 17:14:01 +01:00
operator std : : string ( ) const ;
2013-03-20 10:00:04 +01:00
# endif
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
//! returns pointer to the underlying file node
2010-05-11 19:44:00 +02:00
CvFileNode * operator * ( ) ;
2010-05-25 16:57:10 +02:00
//! returns pointer to the underlying file node
2010-05-11 19:44:00 +02:00
const CvFileNode * operator * ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns iterator pointing to the first node element
2010-05-11 19:44:00 +02:00
FileNodeIterator begin ( ) const ;
2010-05-25 16:57:10 +02:00
//! returns iterator pointing to the element following the last node element
2010-05-11 19:44:00 +02:00
FileNodeIterator end ( ) const ;
2010-05-25 16:57:10 +02:00
//! reads node elements to the buffer with the specified format
2013-03-22 17:37:49 +01:00
void readRaw ( const String & fmt , uchar * vec , size_t len ) const ;
2010-05-25 16:57:10 +02:00
//! reads the registered object and returns pointer to it
2010-05-11 19:44:00 +02:00
void * readObj ( ) const ;
// do not use wrapper pointer classes for better efficiency
const CvFileStorage * fs ;
const CvFileNode * node ;
} ;
2010-05-25 16:57:10 +02:00
/*!
File Node Iterator
2012-05-28 13:22:43 +02:00
2010-05-25 16:57:10 +02:00
The class is used for iterating sequences ( usually ) and mappings .
*/
2010-05-11 19:44:00 +02:00
class CV_EXPORTS FileNodeIterator
{
public :
2010-05-25 16:57:10 +02:00
//! the default constructor
2010-05-11 19:44:00 +02:00
FileNodeIterator ( ) ;
2010-05-25 16:57:10 +02:00
//! the full constructor set to the ofs-th element of the node
2010-05-11 19:44:00 +02:00
FileNodeIterator ( const CvFileStorage * fs , const CvFileNode * node , size_t ofs = 0 ) ;
2010-05-25 16:57:10 +02:00
//! the copy constructor
2010-05-11 19:44:00 +02:00
FileNodeIterator ( const FileNodeIterator & it ) ;
2010-05-25 16:57:10 +02:00
//! returns the currently observed element
2010-05-11 19:44:00 +02:00
FileNode operator * ( ) const ;
2010-05-25 16:57:10 +02:00
//! accesses the currently observed element methods
2010-05-11 19:44:00 +02:00
FileNode operator - > ( ) const ;
2010-05-25 16:57:10 +02:00
//! moves iterator to the next node
FileNodeIterator & operator + + ( ) ;
//! moves iterator to the next node
FileNodeIterator operator + + ( int ) ;
//! moves iterator to the previous node
FileNodeIterator & operator - - ( ) ;
//! moves iterator to the previous node
FileNodeIterator operator - - ( int ) ;
//! moves iterator forward by the specified offset (possibly negative)
2012-05-29 12:36:19 +02:00
FileNodeIterator & operator + = ( int ofs ) ;
2010-05-25 16:57:10 +02:00
//! moves iterator backward by the specified offset (possibly negative)
2012-05-29 12:36:19 +02:00
FileNodeIterator & operator - = ( int ofs ) ;
2010-05-11 19:44:00 +02:00
2010-05-25 16:57:10 +02:00
//! reads the next maxCount elements (or less, if the sequence/mapping last element occurs earlier) to the buffer with the specified format
2013-03-22 17:37:49 +01:00
FileNodeIterator & readRaw ( const String & fmt , uchar * vec ,
2010-05-11 19:44:00 +02:00
size_t maxCount = ( size_t ) INT_MAX ) ;
2012-05-28 13:22:43 +02:00
2010-05-11 19:44:00 +02:00
const CvFileStorage * fs ;
const CvFileNode * container ;
CvSeqReader reader ;
size_t remaining ;
} ;
2012-01-24 21:14:07 +01:00
class CV_EXPORTS Algorithm ;
class CV_EXPORTS AlgorithmInfo ;
struct CV_EXPORTS AlgorithmInfoData ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
template < typename _Tp > struct ParamType { } ;
2012-05-28 13:22:43 +02:00
2011-02-18 11:29:57 +01:00
/*!
Base class for high - level OpenCV algorithms
2012-05-28 13:22:43 +02:00
*/
2012-04-30 16:33:52 +02:00
class CV_EXPORTS_W Algorithm
2011-02-18 11:29:57 +01:00
{
public :
2012-01-24 21:14:07 +01:00
Algorithm ( ) ;
2011-02-18 11:29:57 +01:00
virtual ~ Algorithm ( ) ;
2013-03-22 17:37:49 +01:00
String name ( ) const ;
2012-05-28 13:22:43 +02:00
2013-03-22 17:37:49 +01:00
template < typename _Tp > typename ParamType < _Tp > : : member_type get ( const String & name ) const ;
2012-01-24 21:14:07 +01:00
template < typename _Tp > typename ParamType < _Tp > : : member_type get ( const char * name ) const ;
2012-05-28 13:22:43 +02:00
2013-03-22 17:37:49 +01:00
CV_WRAP int getInt ( const String & name ) const ;
CV_WRAP double getDouble ( const String & name ) const ;
CV_WRAP bool getBool ( const String & name ) const ;
CV_WRAP String getString ( const String & name ) const ;
CV_WRAP Mat getMat ( const String & name ) const ;
CV_WRAP std : : vector < Mat > getMatVector ( const String & name ) const ;
CV_WRAP Ptr < Algorithm > getAlgorithm ( const String & name ) const ;
void set ( const String & name , int value ) ;
void set ( const String & name , double value ) ;
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 std : : vector < Mat > & value ) ;
void set ( const String & name , const Ptr < Algorithm > & value ) ;
template < typename _Tp > void set ( const String & name , const Ptr < _Tp > & value ) ;
CV_WRAP void setInt ( const String & name , int value ) ;
CV_WRAP void setDouble ( const String & name , double value ) ;
CV_WRAP void setBool ( const String & name , bool value ) ;
CV_WRAP void setString ( const String & name , const String & value ) ;
CV_WRAP void setMat ( const String & name , const Mat & value ) ;
CV_WRAP void setMatVector ( const String & name , const std : : vector < Mat > & value ) ;
CV_WRAP void setAlgorithm ( const String & name , const Ptr < Algorithm > & value ) ;
template < typename _Tp > void setAlgorithm ( const String & name , const Ptr < _Tp > & value ) ;
2012-10-23 19:37:27 +02:00
2012-03-15 15:36:01 +01:00
void set ( const char * name , int value ) ;
void set ( const char * name , double value ) ;
void set ( const char * name , bool value ) ;
2013-03-22 17:37:49 +01:00
void set ( const char * name , const String & value ) ;
2012-03-15 15:36:01 +01:00
void set ( const char * name , const Mat & value ) ;
2013-02-24 17:14:01 +01:00
void set ( const char * name , const std : : vector < Mat > & value ) ;
2012-03-15 15:36:01 +01:00
void set ( const char * name , const Ptr < Algorithm > & value ) ;
2012-06-28 14:17:11 +02:00
template < typename _Tp > void set ( const char * name , const Ptr < _Tp > & value ) ;
2012-05-28 13:22:43 +02:00
2012-10-23 19:37:27 +02:00
void setInt ( const char * name , int value ) ;
void setDouble ( const char * name , double value ) ;
void setBool ( const char * name , bool value ) ;
2013-03-22 17:37:49 +01:00
void setString ( const char * name , const String & value ) ;
2012-10-23 19:37:27 +02:00
void setMat ( const char * name , const Mat & value ) ;
2013-02-24 17:14:01 +01:00
void setMatVector ( const char * name , const std : : vector < Mat > & value ) ;
2012-10-23 19:37:27 +02:00
void setAlgorithm ( const char * name , const Ptr < Algorithm > & value ) ;
template < typename _Tp > void setAlgorithm ( const char * name , const Ptr < _Tp > & value ) ;
2013-03-22 17:37:49 +01:00
CV_WRAP String paramHelp ( const String & name ) const ;
2012-01-24 21:14:07 +01:00
int paramType ( const char * name ) const ;
2013-03-22 17:37:49 +01:00
CV_WRAP int paramType ( const String & name ) const ;
CV_WRAP void getParams ( CV_OUT std : : vector < String > & names ) const ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
virtual void write ( FileStorage & fs ) const ;
virtual void read ( const FileNode & fn ) ;
2012-05-28 13:22:43 +02:00
2011-02-18 11:29:57 +01:00
typedef Algorithm * ( * Constructor ) ( void ) ;
2012-01-24 21:14:07 +01:00
typedef int ( Algorithm : : * Getter ) ( ) const ;
typedef void ( Algorithm : : * Setter ) ( int ) ;
2012-05-28 13:22:43 +02:00
2013-03-22 17:37:49 +01:00
CV_WRAP static void getList ( CV_OUT std : : vector < String > & algorithms ) ;
CV_WRAP static Ptr < Algorithm > _create ( const String & name ) ;
template < typename _Tp > static Ptr < _Tp > create ( const String & name ) ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
virtual AlgorithmInfo * info ( ) const /* TODO: make it = 0 ; */ { return 0 ; }
} ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
class CV_EXPORTS AlgorithmInfo
{
public :
2012-04-30 16:33:52 +02:00
friend class Algorithm ;
2013-03-22 17:37:49 +01:00
AlgorithmInfo ( const String & name , Algorithm : : Constructor create ) ;
2012-01-24 21:14:07 +01:00
~ AlgorithmInfo ( ) ;
void get ( const Algorithm * algo , const char * name , int argType , void * value ) const ;
2012-03-17 10:50:47 +01:00
void addParam_ ( Algorithm & algo , const char * name , int argType ,
2012-05-28 13:22:43 +02:00
void * value , bool readOnly ,
2012-01-24 21:14:07 +01:00
Algorithm : : Getter getter , Algorithm : : Setter setter ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
String paramHelp ( const char * name ) const ;
2012-01-24 21:14:07 +01:00
int paramType ( const char * name ) const ;
2013-03-22 17:37:49 +01:00
void getParams ( std : : vector < String > & names ) const ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
void write ( const Algorithm * algo , FileStorage & fs ) const ;
void read ( Algorithm * algo , const FileNode & fn ) const ;
2013-03-22 17:37:49 +01:00
String name ( ) const ;
2012-05-28 13:22:43 +02:00
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
int & value , bool readOnly = false ,
2012-02-15 22:10:11 +01:00
int ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( int ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
bool & value , bool readOnly = false ,
2012-03-15 15:36:01 +01:00
int ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( int ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
double & value , bool readOnly = false ,
2012-02-15 22:10:11 +01:00
double ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( double ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2013-03-22 17:37:49 +01:00
String & value , bool readOnly = false ,
String ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const String & ) = 0 ,
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
Mat & value , bool readOnly = false ,
2012-02-15 22:10:11 +01:00
Mat ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const Mat & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-04-13 23:50:59 +02:00
void addParam ( Algorithm & algo , const char * name ,
2013-02-24 17:14:01 +01:00
std : : vector < Mat > & value , bool readOnly = false ,
std : : vector < Mat > ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const std : : vector < Mat > & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-03-17 10:50:47 +01:00
void addParam ( Algorithm & algo , const char * name ,
2012-05-28 13:22:43 +02:00
Ptr < Algorithm > & value , bool readOnly = false ,
2012-02-15 22:10:11 +01:00
Ptr < Algorithm > ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const Ptr < Algorithm > & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2013-02-04 17:25:18 +01:00
void addParam ( Algorithm & algo , const char * name ,
float & value , bool readOnly = false ,
float ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( float ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2013-02-04 17:25:18 +01:00
void addParam ( Algorithm & algo , const char * name ,
unsigned int & value , bool readOnly = false ,
unsigned int ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( unsigned int ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2013-02-04 17:25:18 +01:00
void addParam ( Algorithm & algo , const char * name ,
uint64 & value , bool readOnly = false ,
uint64 ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( uint64 ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2013-02-04 17:25:18 +01:00
void addParam ( Algorithm & algo , const char * name ,
uchar & value , bool readOnly = false ,
uchar ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( uchar ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-06-29 09:46:53 +02:00
template < typename _Tp , typename _Base > void addParam ( Algorithm & algo , const char * name ,
Ptr < _Tp > & value , bool readOnly = false ,
Ptr < _Tp > ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const Ptr < _Tp > & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2012-06-29 09:46:53 +02:00
template < typename _Tp > void addParam ( Algorithm & algo , const char * name ,
Ptr < _Tp > & value , bool readOnly = false ,
Ptr < _Tp > ( Algorithm : : * getter ) ( ) = 0 ,
void ( Algorithm : : * setter ) ( const Ptr < _Tp > & ) = 0 ,
2013-03-22 17:37:49 +01:00
const String & help = String ( ) ) ;
2011-02-18 11:29:57 +01:00
protected :
2012-01-24 21:14:07 +01:00
AlgorithmInfoData * data ;
2012-04-30 16:33:52 +02:00
void set ( Algorithm * algo , const char * name , int argType ,
const void * value , bool force = false ) const ;
2012-01-24 21:14:07 +01:00
} ;
struct CV_EXPORTS Param
{
2013-02-28 08:10:40 +01:00
enum { INT = 0 , BOOLEAN = 1 , REAL = 2 , STRING = 3 , MAT = 4 , MAT_VECTOR = 5 , ALGORITHM = 6 , FLOAT = 7 , UNSIGNED_INT = 8 , UINT64 = 9 , UCHAR = 11 } ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
Param ( ) ;
Param ( int _type , bool _readonly , int _offset ,
Algorithm : : Getter _getter = 0 ,
Algorithm : : Setter _setter = 0 ,
2013-03-22 17:37:49 +01:00
const String & _help = String ( ) ) ;
2012-01-24 21:14:07 +01:00
int type ;
int offset ;
bool readonly ;
Algorithm : : Getter getter ;
Algorithm : : Setter setter ;
2013-03-22 17:37:49 +01:00
String help ;
2012-01-24 21:14:07 +01:00
} ;
template < > struct ParamType < bool >
{
typedef bool const_param_type ;
typedef bool member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : BOOLEAN } ;
2012-05-28 13:22:43 +02:00
} ;
2012-01-24 21:14:07 +01:00
template < > struct ParamType < int >
{
typedef int const_param_type ;
typedef int member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : INT } ;
} ;
template < > struct ParamType < double >
{
typedef double const_param_type ;
typedef double member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : REAL } ;
} ;
2013-03-22 17:37:49 +01:00
template < > struct ParamType < String >
2012-01-24 21:14:07 +01:00
{
2013-03-22 17:37:49 +01:00
typedef const String & const_param_type ;
typedef String member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : STRING } ;
} ;
template < > struct ParamType < Mat >
{
typedef const Mat & const_param_type ;
typedef Mat member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : MAT } ;
2011-02-18 11:29:57 +01:00
} ;
2011-04-18 17:14:32 +02:00
2013-02-24 17:14:01 +01:00
template < > struct ParamType < std : : vector < Mat > >
2012-04-13 23:50:59 +02:00
{
2013-02-24 17:14:01 +01:00
typedef const std : : vector < Mat > & const_param_type ;
typedef std : : vector < Mat > member_type ;
2012-05-28 13:22:43 +02:00
2012-04-13 23:50:59 +02:00
enum { type = Param : : MAT_VECTOR } ;
} ;
2012-01-24 21:14:07 +01:00
template < > struct ParamType < Algorithm >
{
typedef const Ptr < Algorithm > & const_param_type ;
typedef Ptr < Algorithm > member_type ;
2012-05-28 13:22:43 +02:00
2012-01-24 21:14:07 +01:00
enum { type = Param : : ALGORITHM } ;
} ;
2012-05-28 13:22:43 +02:00
2012-09-07 15:44:01 +02:00
template < > struct ParamType < float >
2011-05-15 21:25:00 +02:00
{
2012-09-07 15:44:01 +02:00
typedef float const_param_type ;
typedef float member_type ;
2012-10-02 12:34:17 +02:00
2012-09-07 15:44:01 +02:00
enum { type = Param : : FLOAT } ;
2012-09-07 11:24:48 +02:00
} ;
2012-10-02 12:34:17 +02:00
2012-09-07 15:44:01 +02:00
template < > struct ParamType < unsigned >
2012-09-07 11:24:48 +02:00
{
2012-09-07 15:44:01 +02:00
typedef unsigned const_param_type ;
typedef unsigned member_type ;
2012-10-02 12:34:17 +02:00
2012-09-07 15:44:01 +02:00
enum { type = Param : : UNSIGNED_INT } ;
} ;
2011-08-04 18:09:04 +02:00
2012-09-07 15:44:01 +02:00
template < > struct ParamType < uint64 >
{
typedef uint64 const_param_type ;
typedef uint64 member_type ;
2012-10-02 12:34:17 +02:00
2012-09-07 15:44:01 +02:00
enum { type = Param : : UINT64 } ;
} ;
2011-05-15 21:25:00 +02:00
2013-02-04 17:25:18 +01:00
template < > struct ParamType < uchar >
{
typedef uchar const_param_type ;
typedef uchar member_type ;
enum { type = Param : : UCHAR } ;
} ;
2012-09-07 11:24:48 +02:00
2013-03-14 17:10:54 +01:00
} //namespace cv
2010-05-11 19:44:00 +02:00
# include "opencv2/core/operations.hpp"
# include "opencv2/core/mat.hpp"
2013-03-20 10:00:04 +01:00
# include "opencv2/core/cvstd.inl.hpp"
# endif // __cplusplus
2010-05-11 19:44:00 +02:00
# endif /*__OPENCV_CORE_HPP__*/