Skip to content

_InputArray_KindFlag

Core and matricesclassOpenCV 5.0.0
import { _InputArray_KindFlag } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSConstructor or factory
CLASS_InputArray_KindFlag
RETURN TYPEOwned native handle
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Native object: release it with using or delete(). Factories can return null; check before calling methods.

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:

    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.

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

Constructors and members

static KIND_SHIFT

kind shift constant (16), defined by OpenCV for cv::_InputArray.

KIND_SHIFT: _InputArray_KindFlagValue<16>,

static FIXED_TYPE

fixed type constant (0x8000 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

FIXED_TYPE: _InputArray_KindFlagValue<-2147483648>,

static FIXED_SIZE

fixed size constant (0x4000 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

FIXED_SIZE: _InputArray_KindFlagValue<1073741824>,

static KIND_MASK

kind mask constant (31 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

KIND_MASK: _InputArray_KindFlagValue<2031616>,

static NONE

none constant (0 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

NONE: _InputArray_KindFlagValue<0>,

static MAT

mat constant (1 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

MAT: _InputArray_KindFlagValue<65536>,

static MATX

matx constant (2 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

MATX: _InputArray_KindFlagValue<131072>,

static STD_VECTOR

std vector constant (3 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

STD_VECTOR: _InputArray_KindFlagValue<196608>,

static STD_VECTOR_VECTOR

std vector vector constant (4 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

STD_VECTOR_VECTOR: _InputArray_KindFlagValue<262144>,

static STD_VECTOR_MAT

std vector mat constant (5 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

STD_VECTOR_MAT: _InputArray_KindFlagValue<327680>,

static OPENGL_BUFFER

opengl buffer constant (7 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

OPENGL_BUFFER: _InputArray_KindFlagValue<458752>,

static CUDA_HOST_MEM

cuda host mem constant (8 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

CUDA_HOST_MEM: _InputArray_KindFlagValue<524288>,

static CUDA_GPU_MAT

cuda gpu mat constant (9 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

CUDA_GPU_MAT: _InputArray_KindFlagValue<589824>,

static UMAT

umat constant (10 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

UMAT: _InputArray_KindFlagValue<655360>,

static STD_VECTOR_UMAT

std vector umat constant (11 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

STD_VECTOR_UMAT: _InputArray_KindFlagValue<720896>,

static STD_BOOL_VECTOR

std bool vector constant (12 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

STD_BOOL_VECTOR: _InputArray_KindFlagValue<786432>,

static STD_VECTOR_CUDA_GPU_MAT

std vector cuda gpu mat constant (13 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

STD_VECTOR_CUDA_GPU_MAT: _InputArray_KindFlagValue<851968>,

static STD_ARRAY_MAT

std array mat constant (15 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

STD_ARRAY_MAT: _InputArray_KindFlagValue<983040>,

static CUDA_GPU_MATND

cuda gpu matnd constant (16 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

CUDA_GPU_MATND: _InputArray_KindFlagValue<1048576>,

static STD_VECTOR_CUDA_GPU_MAT_ND

std vector cuda gpu mat nd constant (17 << KIND_SHIFT), defined by OpenCV for cv::_InputArray.

STD_VECTOR_CUDA_GPU_MAT_ND: _InputArray_KindFlagValue<1114112>

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.