15

In documentation for example there is:

void cv::absdiff    (   InputArray      src1,
        InputArray      src2,
        OutputArray     dst 
    ) 

Is that the same as:

void cv::absdiff    (   Mat     src1,
            Mat     src2,
            Mat     dst 
        ) 

or:

void cv::absdiff    (   Mat*    src1,
            Mat*    src2,
            Mat*    dst 
        ) 

?

I need this to create new function for example

void absDiffSay(XXX src1, XXX src2, XXX dst)
{
  cv::absdiff(src1,src2,dst);
  cout<<"absdiff"<<endl;
}

1 Answers1

29

From OpenCV doc

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:

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.

So, if you you need that your function can accept both cv::Mat and std::vector<> use InputArray, otherwise use simply cv::Mat.

For sure, don't use Mat*.

Miki
  • 40,887
  • 13
  • 123
  • 202