OpenCV, What is the InputArray?

The 'InputArray' is used usually in OpenCV function parameter.
I think that is made to transfer vector< >, Matx< >, Vec< > and scalar easily.

This is the document on the

InputArray and OutputArray

Many OpenCV functions process dense 2-dimensional or multi-dimensional numerical arrays. Usually, such functions take cpp:class:Mat as parameters, but in some cases it’s more convenient to use std::vector<> (for a point set, for example) or Matx<> (for 3x3 homography matrix and such). To avoid many duplicates in the API, special “proxy” classes have been introduced. The base “proxy” class is InputArray. It is used for passing read-only arrays on a function input. The derived from InputArray class OutputArray is used to specify an output array for a function. Normally, you should not care of those intermediate types (and you should not declare variables of those types explicitly) - it will all just work automatically. You can assume that instead of InputArray/OutputArray you can always use Mat, std::vector<>, Matx<>, Vec<> or Scalar. When a function has an optional input or output array, and you do not have or do not want one, pass cv::noArray().

So I tested the 'InputArray' by programming.
Reference this source code.

using namespace std;

void main()

 ///Test #1
 std::vector< cv::Mat > inImgs;
 inImgs.push_back( cv::imread("S1.jpg") );
 inImgs.push_back( cv::imread("S2.jpg") );
 inImgs.push_back( cv::imread("S3.jpg") );

 cv::InputArray imgs = inImgs; 

 printf("Total = %d, Size=(%d,%d)\n",, imgs.size().width, imgs.size().height );

 std::vector< cv::Mat > inFunction;
 imgs.getMatVector( inFunction ); 

 //Test inFunction



Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

AMP dose run on my pc?, AMP(Accelerated Massive Parallelism)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Optical Flow sample source code using OpenCV

Real-time N camera stitching Class.

OpenCV meanShiftFiltering example source code ( cpu: pyrMeanShiftFiltering, gpu:meanShiftFiltering, gpu:meanShiftSegmentation )

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

Image warping (using opencv findHomography, warpPerspective)