Struct opencv::core::_InputArray

source ·
pub struct _InputArray { /* private fields */ }
Expand 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> >, std::vector<Mat>, std::vector<Mat_<T> >, 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).

Implementations§

Trait Implementations§

source§

impl Boxed for _InputArray

source§

unsafe fn from_raw( ptr: <_InputArray as OpenCVFromExtern>::ExternReceive ) -> Self

Wrap the specified raw pointer Read more
source§

fn into_raw(self) -> <_InputArray as OpenCVTypeExternContainer>::ExternSendMut

Return the underlying raw pointer while consuming this wrapper. Read more
source§

fn as_raw(&self) -> <_InputArray as OpenCVTypeExternContainer>::ExternSend

Return the underlying raw pointer. Read more
source§

fn as_raw_mut( &mut self ) -> <_InputArray as OpenCVTypeExternContainer>::ExternSendMut

Return the underlying mutable raw pointer Read more
source§

impl Debug for _InputArray

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for _InputArray

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<_InputOutputArray> for _InputArray

source§

fn from(s: _InputOutputArray) -> Self

Converts to this type from the input type.
source§

impl From<_OutputArray> for _InputArray

source§

fn from(s: _OutputArray) -> Self

Converts to this type from the input type.
source§

impl ToInputArray for _InputArray

source§

impl _InputArrayTrait for _InputArray

source§

impl _InputArrayTraitConst for _InputArray

source§

fn as_raw__InputArray(&self) -> *const c_void

source§

fn get_mat(&self, idx: i32) -> Result<Mat>

C++ default parameters Read more
source§

fn get_mat_def(&self) -> Result<Mat>

source§

fn get_mat_(&self, idx: i32) -> Result<Mat>

C++ default parameters Read more
source§

fn get_mat__def(&self) -> Result<Mat>

source§

fn get_umat(&self, idx: i32) -> Result<UMat>

C++ default parameters Read more
source§

fn get_umat_def(&self) -> Result<UMat>

source§

fn get_mat_vector(&self, mv: &mut Vector<Mat>) -> Result<()>

source§

fn get_umat_vector(&self, umv: &mut Vector<UMat>) -> Result<()>

source§

fn get_gpu_mat_vector(&self, gpumv: &mut Vector<GpuMat>) -> Result<()>

source§

fn get_gpu_mat(&self) -> Result<GpuMat>

source§

fn get_o_gl_buffer(&self) -> Result<Buffer>

source§

fn get_flags(&self) -> Result<i32>

source§

fn get_obj(&self) -> Result<*mut c_void>

source§

fn get_sz(&self) -> Result<Size>

source§

fn kind(&self) -> Result<_InputArray_KindFlag>

source§

fn dims(&self, i: i32) -> Result<i32>

C++ default parameters Read more
source§

fn dims_def(&self) -> Result<i32>

source§

fn cols(&self, i: i32) -> Result<i32>

C++ default parameters Read more
source§

fn cols_def(&self) -> Result<i32>

source§

fn rows(&self, i: i32) -> Result<i32>

C++ default parameters Read more
source§

fn rows_def(&self) -> Result<i32>

source§

fn size(&self, i: i32) -> Result<Size>

C++ default parameters Read more
source§

fn size_def(&self) -> Result<Size>

source§

fn sizend(&self, sz: &mut i32, i: i32) -> Result<i32>

C++ default parameters Read more
source§

fn sizend_def(&self, sz: &mut i32) -> Result<i32>

source§

fn same_size(&self, arr: &impl ToInputArray) -> Result<bool>

source§

fn total(&self, i: i32) -> Result<size_t>

C++ default parameters Read more
source§

fn total_def(&self) -> Result<size_t>

source§

fn typ(&self, i: i32) -> Result<i32>

C++ default parameters Read more
source§

fn typ_def(&self) -> Result<i32>

source§

fn depth(&self, i: i32) -> Result<i32>

C++ default parameters Read more
source§

fn depth_def(&self) -> Result<i32>

source§

fn channels(&self, i: i32) -> Result<i32>

C++ default parameters Read more
source§

fn channels_def(&self) -> Result<i32>

source§

fn is_continuous(&self, i: i32) -> Result<bool>

C++ default parameters Read more
source§

fn is_continuous_def(&self) -> Result<bool>

source§

fn is_submatrix(&self, i: i32) -> Result<bool>

C++ default parameters Read more
source§

fn is_submatrix_def(&self) -> Result<bool>

source§

fn empty(&self) -> Result<bool>

source§

fn copy_to(&self, arr: &mut impl ToOutputArray) -> Result<()>

source§

fn copy_to_masked( &self, arr: &mut impl ToOutputArray, mask: &impl ToInputArray ) -> Result<()>

source§

fn offset(&self, i: i32) -> Result<size_t>

C++ default parameters Read more
source§

fn offset_def(&self) -> Result<size_t>

source§

fn step(&self, i: i32) -> Result<size_t>

C++ default parameters Read more
source§

fn step_def(&self) -> Result<size_t>

source§

fn is_mat(&self) -> Result<bool>

source§

fn is_umat(&self) -> Result<bool>

source§

fn is_mat_vector(&self) -> Result<bool>

source§

fn is_umat_vector(&self) -> Result<bool>

source§

fn is_matx(&self) -> Result<bool>

source§

fn is_vector(&self) -> Result<bool>

source§

fn is_gpu_mat(&self) -> Result<bool>

source§

fn is_gpu_mat_vector(&self) -> Result<bool>

source§

impl Send for _InputArray

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Mat> ModifyInplace for Mat
where Mat: Boxed,

source§

unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res ) -> Res

Helper function to call OpenCV functions that allow in-place modification of a Mat or another similar object. By passing a mutable reference to the Mat to this function your closure will get called with the read reference and a write references to the same Mat. This is of course unsafe as it breaks the Rust aliasing rules, but it might be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place modification is imgproc::threshold. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.