[opencv] 对C++版中 Mat结构的理解

版权声明:本文为博主原创文章,未经博主允许禁止转载! https://blog.csdn.net/az9996/article/details/89736462

这是定位到的源码,比较长这里只粘贴部分内容

class CV_EXPORTS Mat
{
public:
    /**
    These are various constructors that form a matrix. As noted in the AutomaticAllocation, often
    the default constructor is enough, and the proper matrix will be allocated by an OpenCV function.
    The constructed matrix can further be assigned to another matrix or matrix expression or can be
    allocated with Mat::create . In the former case, the old content is de-referenced.
    
    这些是构成矩阵的各种构造函数。正如AutomaticAllocation中所指出的,通常默认构造函数就足够了,
    适当的矩阵将由OpenCV函数分配。所构造的矩阵可以进一步分配给另一个矩阵或矩阵表达式,
    也可以用Mat::create分配。在前一种情况下,旧内容被取消引用。
     */
    Mat();

CV_EXPORTS在宏定义中进行了定义,总共找到了3处

在这里插入图片描述
第一处:

#ifndef CV_EXPORTS
# define CV_EXPORTS
#endif

第二处:

#ifdef CVAPI_EXPORTS
# if (defined _WIN32 || defined WINCE || defined __CYGWIN__)
#   define CV_EXPORTS __declspec(dllexport)
# elif defined __GNUC__ && __GNUC__ >= 4
#   define CV_EXPORTS __attribute__ ((visibility ("default")))
# endif
#endif

第三处:

#ifdef CVAPI_EXPORTS
# if (defined _WIN32 || defined WINCE || defined __CYGWIN__)
#   define CV_EXPORTS __declspec(dllexport)
# elif defined __GNUC__ && __GNUC__ >= 4
#   define CV_EXPORTS __attribute__ ((visibility ("default")))
# endif
#endif

简单的理解

Mat是opencv中定义的类,通过类实例化方法,构建Mat对象,在此基础上即可对实例对象调用函数(C++是一门面向对象的语言)。
Mat是沟通现实与opencv程序之间的桥梁。
所以,对于图片要先构建Mat对象,然后再进行操作。

OpenCV使用这个结构来处理所有类型的图像:单通道、多通道、整形、浮点数以及各种类型。

猜你喜欢

转载自blog.csdn.net/az9996/article/details/89736462