图像在计算机是用矩阵存储的

    image.png image.png image.png

    cv::Mat class

    1. class CV_EXPORTS Mat
    2. {
    3. public:
    4. int rows, cols;
    5. //pointer to data
    6. uchar* data;
    7. //size_t step.p
    8. MatStep step;
    9. ...
    10. };

    Matrix: 2D array? Much more than that.
    modules/core/include/opencv2/core/mat.hpp

    image.png
    refcount,如果有一个头a,还有一个头b,将a赋值给b,其实是将成员变量赋值给b,那么a b同时指向一块内存空间,如果更多的头指向呢?那么谁来释放内存? -> 引用计数

    opencv在申请内存时,会多申请4个字节,其会记录这段内存空间被多少头引用。如果有头指向这块内存空间,refcount+1,如果有的头被释放掉,refcount-1,当其值为0时,要释放此内存空间。

    step in cv::Mat
    How many bytes for a row of Matrix 4(row)x3(col)?

    • Can be 3, 4, 8, and any other values >=3.
    • Memory alignment for SIMD

    为了内存对齐。
    image.png