简体   繁体   English

OpenCV Mat 的逗号分隔初始化器是如何用 C++ 实现的?

[英]How is the comma-separated initializer of OpenCV Mat implemented with 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 the comma-separated initializer of OpenCV Mat implemented with C++? OpenCV Mat 的逗号分隔初始化器是如何用 C++ 实现的?

How does the "1" get into the Mat after the "0"?在“0”之后,“1”如何进入垫子?

To allow an initialization like允许像这样的初始化

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

OpenCV first uses OpenCV 首次使用

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

to return an intermediate object MatCommaInitializer_<T> .返回一个中间对象MatCommaInitializer_<T> This object has an overloaded operator, , namely这个对象有一个重载的operator, ,即

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

which adds the value to the initializer.它将值添加到初始化程序。 Then there is a constructor然后有一个构造函数

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

to create a Mat object from a MatCommaInitializer .MatCommaInitializer创建一个Mat对象。

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 ).注意:您可以在 OpenCV 文档http://docs.opencv.org/master/ ( http://docs.opencv.org/master/d6/d9e/classcv_1_1MatCommaInitializer__.html ) 中找到此类信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM