OpenCV  3.0.0-rc1
Open Source Computer Vision
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cv::_InputArray Class Reference

This is the proxy class for passing read-only input arrays into OpenCV functions. More...

#include "mat.hpp"

Inheritance diagram for cv::_InputArray:
cv::_OutputArray cv::_InputOutputArray

Public Types

enum  {
  KIND_SHIFT = 16,
  FIXED_TYPE = 0x8000 << KIND_SHIFT,
  FIXED_SIZE = 0x4000 << KIND_SHIFT,
  KIND_MASK = 31 << KIND_SHIFT,
  NONE = 0 << KIND_SHIFT,
  MAT = 1 << KIND_SHIFT,
  MATX = 2 << KIND_SHIFT,
  STD_VECTOR = 3 << KIND_SHIFT,
  STD_VECTOR_VECTOR = 4 << KIND_SHIFT,
  STD_VECTOR_MAT = 5 << KIND_SHIFT,
  EXPR = 6 << KIND_SHIFT,
  OPENGL_BUFFER = 7 << KIND_SHIFT,
  CUDA_HOST_MEM = 8 << KIND_SHIFT,
  CUDA_GPU_MAT = 9 << KIND_SHIFT,
  UMAT =10 << KIND_SHIFT,
  STD_VECTOR_UMAT =11 << KIND_SHIFT
}
 

Public Member Functions

 _InputArray ()
 
 _InputArray (int _flags, void *_obj)
 
 _InputArray (const Mat &m)
 
 _InputArray (const MatExpr &expr)
 
 _InputArray (const std::vector< Mat > &vec)
 
template<typename _Tp >
 _InputArray (const Mat_< _Tp > &m)
 
template<typename _Tp >
 _InputArray (const std::vector< _Tp > &vec)
 
template<typename _Tp >
 _InputArray (const std::vector< std::vector< _Tp > > &vec)
 
template<typename _Tp >
 _InputArray (const std::vector< Mat_< _Tp > > &vec)
 
template<typename _Tp >
 _InputArray (const _Tp *vec, int n)
 
template<typename _Tp , int m, int n>
 _InputArray (const Matx< _Tp, m, n > &matx)
 
 _InputArray (const double &val)
 
 _InputArray (const cuda::GpuMat &d_mat)
 
 _InputArray (const ogl::Buffer &buf)
 
 _InputArray (const cuda::HostMem &cuda_mem)
 
template<typename _Tp >
 _InputArray (const cudev::GpuMat_< _Tp > &m)
 
 _InputArray (const UMat &um)
 
 _InputArray (const std::vector< UMat > &umv)
 
 ~_InputArray ()
 
int channels (int i=-1) const
 
int cols (int i=-1) const
 
void copyTo (const _OutputArray &arr) const
 
void copyTo (const _OutputArray &arr, const _InputArray &mask) const
 
int depth (int i=-1) const
 
int dims (int i=-1) const
 
bool empty () const
 
int getFlags () const
 
cuda::GpuMat getGpuMat () const
 
Mat getMat (int idx=-1) const
 
Mat getMat_ (int idx=-1) const
 
void getMatVector (std::vector< Mat > &mv) const
 
void * getObj () const
 
ogl::Buffer getOGlBuffer () const
 
Size getSz () const
 
UMat getUMat (int idx=-1) const
 
void getUMatVector (std::vector< UMat > &umv) const
 
bool isContinuous (int i=-1) const
 
bool isMat () const
 
bool isMatVector () const
 
bool isMatx () const
 
bool isSubmatrix (int i=-1) const
 
bool isUMat () const
 
bool isUMatVector () const
 
int kind () const
 
size_t offset (int i=-1) const
 
int rows (int i=-1) const
 
bool sameSize (const _InputArray &arr) const
 
Size size (int i=-1) const
 
int sizend (int *sz, int i=-1) const
 
size_t step (int i=-1) const
 
size_t total (int i=-1) const
 
int type (int i=-1) const
 

Protected Member Functions

void init (int _flags, const void *_obj)
 
void init (int _flags, const void *_obj, Size _sz)
 

Protected Attributes

int flags
 
void * obj
 
Size sz
 

Detailed Description

This is the proxy class for passing read-only input arrays into OpenCV functions.

It is defined as:

typedef const _InputArray& InputArray;

where _InputArray is a class that can be constructed from Mat, Mat_<T>, Matx<T, m, n>, std::vector<T>, std::vector<std::vector<T> > or std::vector<Mat>. It can also be constructed from a matrix expression.

Since this is mostly implementation-level class, and its interface may change in future versions, we do not describe it in details. There are a few key things, though, that should be kept in mind:

Here is how you can use a function that takes InputArray :

std::vector<Point2f> vec;
// points or a circle
for( int i = 0; i < 30; i++ )
vec.push_back(Point2f((float)(100 + 30*cos(i*CV_PI*2/5)),
(float)(100 - 30*sin(i*CV_PI*2/5))));
cv::transform(vec, vec, cv::Matx23f(0.707, -0.707, 10, 0.707, 0.707, 20));

That is, we form an STL vector containing points, and apply in-place affine transformation to the vector using the 2x3 matrix created inline as Matx<float, 2, 3> instance.

Here is how such a function can be implemented (for simplicity, we implement a very specific case of it, according to the assertion statement inside) :

void myAffineTransform(InputArray _src, OutputArray _dst, InputArray _m)
{
// get Mat headers for input arrays. This is O(1) operation,
// unless _src and/or _m are matrix expressions.
Mat src = _src.getMat(), m = _m.getMat();
CV_Assert( src.type() == CV_32FC2 && m.type() == CV_32F && m.size() == Size(3, 2) );
// [re]create the output array so that it has the proper size and type.
// In case of Mat it calls Mat::create, in case of STL vector it calls vector::resize.
_dst.create(src.size(), src.type());
Mat dst = _dst.getMat();
for( int i = 0; i < src.rows; i++ )
for( int j = 0; j < src.cols; j++ )
{
Point2f pt = src.at<Point2f>(i, j);
dst.at<Point2f>(i, j) = Point2f(m.at<float>(0, 0)*pt.x +
m.at<float>(0, 1)*pt.y +
m.at<float>(0, 2),
m.at<float>(1, 0)*pt.x +
m.at<float>(1, 1)*pt.y +
m.at<float>(1, 2));
}
}

There is another related type, InputArrayOfArrays, which is currently defined as a synonym for InputArray:

typedef InputArray InputArrayOfArrays;

It denotes function arguments that are either vectors of vectors or vectors of matrices. A separate synonym is needed to generate Python/Java etc. wrappers properly. At the function implementation level their use is similar, but _InputArray::getMat(idx) should be used to get header for the idx-th component of the outer vector and _InputArray::size().area() should be used to find the number of components (vectors/matrices) of the outer vector.

Examples:
pca.cpp.

Member Enumeration Documentation

anonymous enum
Enumerator
KIND_SHIFT 
FIXED_TYPE 
FIXED_SIZE 
KIND_MASK 
NONE 
MAT 
MATX 
STD_VECTOR 
STD_VECTOR_VECTOR 
STD_VECTOR_MAT 
EXPR 
OPENGL_BUFFER 
CUDA_HOST_MEM 
CUDA_GPU_MAT 
UMAT 
STD_VECTOR_UMAT 

Constructor & Destructor Documentation

cv::_InputArray::_InputArray ( )
cv::_InputArray::_InputArray ( int  _flags,
void *  _obj 
)
cv::_InputArray::_InputArray ( const Mat m)
cv::_InputArray::_InputArray ( const MatExpr expr)
cv::_InputArray::_InputArray ( const std::vector< Mat > &  vec)
template<typename _Tp >
cv::_InputArray::_InputArray ( const Mat_< _Tp > &  m)
template<typename _Tp >
cv::_InputArray::_InputArray ( const std::vector< _Tp > &  vec)
template<typename _Tp >
cv::_InputArray::_InputArray ( const std::vector< std::vector< _Tp > > &  vec)
template<typename _Tp >
cv::_InputArray::_InputArray ( const std::vector< Mat_< _Tp > > &  vec)
template<typename _Tp >
cv::_InputArray::_InputArray ( const _Tp *  vec,
int  n 
)
template<typename _Tp , int m, int n>
cv::_InputArray::_InputArray ( const Matx< _Tp, m, n > &  matx)
cv::_InputArray::_InputArray ( const double &  val)
cv::_InputArray::_InputArray ( const cuda::GpuMat d_mat)
cv::_InputArray::_InputArray ( const ogl::Buffer buf)
cv::_InputArray::_InputArray ( const cuda::HostMem cuda_mem)
template<typename _Tp >
cv::_InputArray::_InputArray ( const cudev::GpuMat_< _Tp > &  m)
cv::_InputArray::_InputArray ( const UMat um)
cv::_InputArray::_InputArray ( const std::vector< UMat > &  umv)
cv::_InputArray::~_InputArray ( )

Member Function Documentation

int cv::_InputArray::channels ( int  i = -1) const
int cv::_InputArray::cols ( int  i = -1) const
void cv::_InputArray::copyTo ( const _OutputArray arr) const
void cv::_InputArray::copyTo ( const _OutputArray arr,
const _InputArray mask 
) const
int cv::_InputArray::depth ( int  i = -1) const
int cv::_InputArray::dims ( int  i = -1) const
bool cv::_InputArray::empty ( ) const
int cv::_InputArray::getFlags ( ) const
cuda::GpuMat cv::_InputArray::getGpuMat ( ) const
Mat cv::_InputArray::getMat ( int  idx = -1) const
Examples:
pca.cpp.
Mat cv::_InputArray::getMat_ ( int  idx = -1) const
void cv::_InputArray::getMatVector ( std::vector< Mat > &  mv) const
void* cv::_InputArray::getObj ( ) const
ogl::Buffer cv::_InputArray::getOGlBuffer ( ) const
Size cv::_InputArray::getSz ( ) const
UMat cv::_InputArray::getUMat ( int  idx = -1) const
void cv::_InputArray::getUMatVector ( std::vector< UMat > &  umv) const
void cv::_InputArray::init ( int  _flags,
const void *  _obj 
)
protected
void cv::_InputArray::init ( int  _flags,
const void *  _obj,
Size  _sz 
)
protected
bool cv::_InputArray::isContinuous ( int  i = -1) const
bool cv::_InputArray::isMat ( ) const
bool cv::_InputArray::isMatVector ( ) const
bool cv::_InputArray::isMatx ( ) const
bool cv::_InputArray::isSubmatrix ( int  i = -1) const
bool cv::_InputArray::isUMat ( ) const
bool cv::_InputArray::isUMatVector ( ) const
int cv::_InputArray::kind ( ) const
size_t cv::_InputArray::offset ( int  i = -1) const
int cv::_InputArray::rows ( int  i = -1) const
bool cv::_InputArray::sameSize ( const _InputArray arr) const
Size cv::_InputArray::size ( int  i = -1) const
int cv::_InputArray::sizend ( int *  sz,
int  i = -1 
) const
size_t cv::_InputArray::step ( int  i = -1) const
size_t cv::_InputArray::total ( int  i = -1) const
int cv::_InputArray::type ( int  i = -1) const

Member Data Documentation

int cv::_InputArray::flags
protected
void* cv::_InputArray::obj
protected
Size cv::_InputArray::sz
protected

The documentation for this class was generated from the following file: