Class cv::_InputArray#

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

Collaboration diagram for cv::_InputArray:

Public Types#

enum KindFlag {
    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,
    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,
    STD_BOOL_VECTOR =12 << KIND_SHIFT,
    STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT,
    STD_ARRAY_MAT =15 << KIND_SHIFT,
    CUDA_GPU_MATND =16 << KIND_SHIFT,
    STD_VECTOR_CUDA_GPU_MAT_ND = 17 << KIND_SHIFT
}

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 cv::_InputArray is a class that can be constructed from cv::Mat, cv::Mat_<T>, cv::Matx<T, m, n>, std::vector<T>, std::vector<std::vector<T>>, std::vector<Mat>, std::vector<Mat_<T>>, cv::UMat, std::vector<UMat> or double. 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:

  • When you see in the reference manual or in OpenCV source code a function that takes InputArray, it means that you can actually pass Mat, Matx, vector<T> etc. (see above the complete list).

  • Optional input arguments: If some of the input arrays may be empty, pass cv::noArray() (or simply cv::Mat() as you probably did before).

  • The class is designed solely for passing parameters. That is, normally you should not declare class members, local and global variables of this type.

  • If you want to design your own function or a class method that can operate of arrays of multiple types, you can use InputArray (or OutputArray) for the respective parameters. Inside a function you should use _InputArray::getMat() method to construct a matrix header for the array (without copying data). _InputArray::kind() can be used to distinguish Mat from vector<> etc., but normally it is not needed.

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: 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.

In general, type support is limited to cv::Mat types. Other types are forbidden. But in some cases we need to support passing of custom non-general Mat types, like arrays of cv::KeyPoint, cv::DMatch, etc. This data is not intended to be interpreted as an image data, or processed somehow like regular cv::Mat. To pass such custom type use rawIn() / rawOut() / rawInOut() wrappers. Custom type is wrapped as Mat-compatible CV_8UC<N> values (N = sizeof(T), N <= CV_CN_MAX).

Examples
samples/peopledetect.cpp, and samples/cpp/pca.cpp.

Member Enumeration Documentation#

enum KindFlag

KIND_SHIFT
Python: cv._InputArray_KIND_SHIFT

FIXED_TYPE
Python: cv._InputArray_FIXED_TYPE

FIXED_SIZE
Python: cv._InputArray_FIXED_SIZE

KIND_MASK
Python: cv._InputArray_KIND_MASK

NONE
Python: cv._InputArray_NONE

MAT
Python: cv._InputArray_MAT

MATX
Python: cv._InputArray_MATX

STD_VECTOR
Python: cv._InputArray_STD_VECTOR

STD_VECTOR_VECTOR
Python: cv._InputArray_STD_VECTOR_VECTOR

STD_VECTOR_MAT
Python: cv._InputArray_STD_VECTOR_MAT

OPENGL_BUFFER
Python: cv._InputArray_OPENGL_BUFFER

CUDA_HOST_MEM
Python: cv._InputArray_CUDA_HOST_MEM

CUDA_GPU_MAT
Python: cv._InputArray_CUDA_GPU_MAT

UMAT
Python: cv._InputArray_UMAT

STD_VECTOR_UMAT
Python: cv._InputArray_STD_VECTOR_UMAT

STD_BOOL_VECTOR
Python: cv._InputArray_STD_BOOL_VECTOR

STD_VECTOR_CUDA_GPU_MAT
Python: cv._InputArray_STD_VECTOR_CUDA_GPU_MAT

STD_ARRAY_MAT
Python: cv._InputArray_STD_ARRAY_MAT

CUDA_GPU_MATND
Python: cv._InputArray_CUDA_GPU_MATND

STD_VECTOR_CUDA_GPU_MAT_ND
Python: cv._InputArray_STD_VECTOR_CUDA_GPU_MAT_ND

Constructor & Destructor Documentation#

_InputArray()#

cv::_InputArray::_InputArray()

_InputArray()#

template<typename _Tp>
cv::_InputArray::_InputArray(
const _Tp * vec,
int n )

_InputArray()#

cv::_InputArray::_InputArray(const cuda::GpuMat & d_mat)

_InputArray()#

cv::_InputArray::_InputArray(const cuda::GpuMatND & d_mat)

_InputArray()#

cv::_InputArray::_InputArray(const cuda::HostMem & cuda_mem)

_InputArray()#

template<typename _Tp>
cv::_InputArray::InputArray(const cudev::GpuMat< _Tp > & m)

_InputArray()#

cv::_InputArray::_InputArray(const double & val)

_InputArray()#

cv::_InputArray::_InputArray(const Mat & m)

_InputArray()#

template<typename _Tp>
cv::_InputArray::InputArray(const Mat< _Tp > & m)

_InputArray()#

cv::_InputArray::_InputArray(const MatExpr & expr)

_InputArray()#

template<typename _Tp, int m, int n>
cv::_InputArray::_InputArray(const Matx< _Tp, m, n > & matx)

_InputArray()#

cv::_InputArray::_InputArray(const ogl::Buffer & buf)

_InputArray()#

template<typename _Tp, std::size_t _Nm>
cv::_InputArray::_InputArray(const std::array< _Tp, _Nm > & arr)

_InputArray()#

template<std::size_t _Nm>
cv::_InputArray::_InputArray(const std::array< Mat, _Nm > & arr)

_InputArray()#

template<typename _Tp>
cv::_InputArray::_InputArray(const std::vector< _Tp > & vec)

_InputArray()#

cv::_InputArray::_InputArray(const std::vector< bool > & vec)

_InputArray()#

cv::_InputArray::_InputArray(const std::vector< cuda::GpuMat > & d_mat_array)

_InputArray()#

cv::_InputArray::_InputArray(const std::vector< cuda::GpuMatND > & d_mat_array)

_InputArray()#

cv::_InputArray::_InputArray(const std::vector< Mat > & vec)

_InputArray()#

template<typename _Tp>
cv::_InputArray::InputArray(const std::vector< Mat< _Tp > > & vec)

_InputArray()#

template<typename _Tp>
cv::_InputArray::_InputArray(const std::vector< std::vector< _Tp > > & vec)

_InputArray()#

cv::_InputArray::_InputArray(const std::vector< std::vector< bool > > &)

_InputArray()#

cv::_InputArray::_InputArray(const std::vector< UMat > & umv)

_InputArray()#

cv::_InputArray::_InputArray(const UMat & um)

_InputArray()#

cv::_InputArray::_InputArray(
int _flags,
void * _obj )

~_InputArray()#

cv::_InputArray::~_InputArray()

Member Function Documentation#

channels()#

int cv::_InputArray::channels(int i = -1)

cols()#

int cv::_InputArray::cols(int i = -1)

copyTo()#

void cv::_InputArray::copyTo(const _OutputArray & arr)

copyTo()#

void cv::_InputArray::copyTo(
const _OutputArray & arr,
const _InputArray & mask )

depth()#

int cv::_InputArray::depth(int i = -1)

dims()#

int cv::_InputArray::dims(int i = -1)

empty()#

bool cv::_InputArray::empty()

empty()#

bool cv::_InputArray::empty(int i)

getFlags()#

int cv::_InputArray::getFlags()

getGpuMat()#

cuda::GpuMat cv::_InputArray::getGpuMat()

getGpuMatND()#

cuda::GpuMatND cv::_InputArray::getGpuMatND()

getGpuMatNDVector()#

void cv::_InputArray::getGpuMatNDVector(std::vector< cuda::GpuMatND > & gpumv)

getGpuMatVector()#

void cv::_InputArray::getGpuMatVector(std::vector< cuda::GpuMat > & gpumv)

getMat()#

Mat cv::_InputArray::getMat(int idx = -1)

getMat_()#

Mat cv::InputArray::getMat(int idx = -1)

getMatVector()#

void cv::_InputArray::getMatVector(std::vector< Mat > & mv)

getObj()#

void * cv::_InputArray::getObj()

getOGlBuffer()#

ogl::Buffer cv::_InputArray::getOGlBuffer()

getSz()#

Size cv::_InputArray::getSz()

getUMat()#

UMat cv::_InputArray::getUMat(int idx = -1)

getUMatVector()#

void cv::_InputArray::getUMatVector(std::vector< UMat > & umv)

isContinuous()#

bool cv::_InputArray::isContinuous(int i = -1)

isGpuMat()#

bool cv::_InputArray::isGpuMat()

isGpuMatND()#

bool cv::_InputArray::isGpuMatND()

isGpuMatVector()#

bool cv::_InputArray::isGpuMatVector()

isMat()#

bool cv::_InputArray::isMat()

isMatVector()#

bool cv::_InputArray::isMatVector()

isMatx()#

bool cv::_InputArray::isMatx()

isSubmatrix()#

bool cv::_InputArray::isSubmatrix(int i = -1)

isUMat()#

bool cv::_InputArray::isUMat()

isUMatVector()#

bool cv::_InputArray::isUMatVector()

isVector()#

bool cv::_InputArray::isVector()

isVecVector()#

bool cv::_InputArray::isVecVector()

kind()#

_InputArray::KindFlag cv::_InputArray::kind()

offset()#

size_t cv::_InputArray::offset(int i = -1)

rows()#

int cv::_InputArray::rows(int i = -1)

sameSize()#

bool cv::_InputArray::sameSize(const _InputArray & arr)

shape()#

MatShape cv::_InputArray::shape(int i = -1)

size()#

Size cv::_InputArray::size(int i = -1)

sizend()#

int cv::_InputArray::sizend(
int * sz,
int i = -1 )

step()#

size_t cv::_InputArray::step(int i = -1)

total()#

size_t cv::_InputArray::total(int i = -1)

type()#

int cv::_InputArray::type(int i = -1)

rawIn()#

template<typename _Tp, std::size_t _Nm>
static _InputArray cv::_InputArray::rawIn(const std::array< _Tp, _Nm > & arr)

rawIn()#

template<typename _Tp>
static _InputArray cv::_InputArray::rawIn(const std::vector< _Tp > & vec)

init()#

void cv::_InputArray::init(
int _flags,
const void * _obj )

init()#

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

Member Data Documentation#

flags#

int cv::_InputArray::flags

obj#

void * cv::_InputArray::obj

sz#

Size cv::_InputArray::sz

Source file#

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