我正忙于学习 OpenCV,但有一部分我不明白。这可能是一个容易回答的问题,但我仍然被困住了,非常感谢您的回答。在OpenCV中,矩阵的实现方式如下:
typedef struct CvMat {
int type;
int step;
int* refcount;
union {
uchar* ptr;
short* s;
int* i;
float* fl;
double* db;
} data;
union {
int rows;
int height;
};
union {
int cols;
int width;
};
} CvMat;
据我了解, union 意味着 int rows
和 int height
共享相同的内存位置。如果是这样,我希望行数和高度始终具有相同的值。那将意味着我们只能有方阵,我认为在 OpenCV 中不是这种情况。那么,即使它是并集,我们怎么能有两个不同的行和高度值呢?有人能告诉我这个结构是如何工作的吗?
非常感谢!
最佳答案
这里,rows
表示“行数”,与height
本质上是一样的。同样,cols
表示“列数”,只是 width
的别名。它们在其他上下文中不一定是别名,但就 OpenCV 而言,它们被视为别名。
这可能是出于向后兼容的原因,因为 the official website lists only rows
and cols
.此外,请注意:
CvMat
is now obsolete; consider usingMat
instead.
关于c++ - 这个 OpenCV 库中如何使用 union ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27721409/