1. 程式人生 > >CvMat 和cv::Mat之間的區別

CvMat 和cv::Mat之間的區別

cv::Mat是一個類(Class),而CvMat是一個Struct,從型別上就可以知道二者存在很大區別。前者除了幾個成員變數之外還有很多的成員函式和過載函式,可以實現很多的影象資料處理功能,而後者只有幾個成員變數,要對其成員進行一些處理,需要借用別的函式。

typedef struct CvMat
{
int type;
int step;
/* for internal use only */
int* refcount;
int hdr_refcount;
union //資料的指標
{
uchar* ptr;
short* s;
int* i;
float* fl;
double* db;
} data;
#ifdef __cplusplus 
union { int rows; int height; }; union { int cols; int width; }; #else int rows; int cols; #endif } CvMat; CvMat中的data資料只是矩陣資料的首地址,分配的記憶體大小為行列乘積。對該記憶體塊的操作需要呼叫函式,也可以使用指標索引。