How is comma delimited initializer for OpenCV Mat implemented using C ++?

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main() {
    Mat a = (Mat_<double>(3, 3) << 0, 1, 2, 3, 4, 5, 6, 7, 8);

    cout << a << endl;

    return 0;
}

      

How is comma delimited initializer for OpenCV Mat implemented with C ++?

How does "1" get into the matrix after "0"?

+3


source to share


1 answer


To allow initialization like

Mat a = (Mat_<double>(3, 3) << 0, 1, 2, 3, 4, 5, 6, 7, 8);

      

OpenCV first uses

template <typename T>
MatCommaInitializer_<T> operator<<(Mat_<T>&, T);

      

to return an intermediate object MatCommaInitializer_<T>

. This object has an overload operator,

, namely



template <typename T2>
MatCommaInitializer_<T>& operator,(T2 v);

      

which adds value to the initializer. Then there is a constructor

template <typename T>
explicit Mat(MatCommaInitializer_<T> const&);

      

to create an object Mat

from MatCommaInitializer

.

Note. You can find such information in the OpenCV documentation http://docs.opencv.org/master/ ( http://docs.opencv.org/master/d6/d9e/classcv_1_1MatCommaInitializer__.html ).

+6


source







All Articles