设为首页 加入收藏

TOP

Opencv笔记(1) 数据结构的命名规则(CvMat,...)
2015-07-20 17:32:08 来源: 作者: 【 】 浏览:2
Tags:Opencv 笔记 数据结构 命名 规则 CvMat ...

网上查了很多,发现查资料不如查源码

以Cv为开头的类,都是不含有具体数据的(仅仅存储指针)

CvMat

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;


CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL))
{
    CvMat m;

    assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
    type = CV_MAT_TYPE(type);
    m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;
    m.cols = cols;
    m.rows = rows;
    m.step = m.cols*CV_ELEM_SIZE(type);
    m.data.ptr = (uchar*)data;
    m.refcount = NULL;
    m.hdr_refcount = 0;

    return m;
}





CV_INLINE ?double ?cvmGet( const CvMat* mat, int row, int col )
{//低效率访问!
? ? int type;


? ? type = CV_MAT_TYPE(mat->type);
? ? assert( (unsigned)row < (unsigned)mat->rows &&
? ? ? ? ? ? (unsigned)col < (unsigned)mat->cols );


? ? if( type == CV_32FC1 )
? ? ? ? return ((float*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col];
? ? else
? ? {
? ? ? ? assert( type == CV_64FC1 );
? ? ? ? return ((double*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col];
? ? }
}




CV_INLINE ?void ?cvmSet( CvMat* mat, int row, int col, double value )
{
? ? int type;
? ? type = CV_MAT_TYPE(mat->type);
? ? assert( (unsigned)row < (unsigned)mat->rows &&
? ? ? ? ? ? (unsigned)col < (unsigned)mat->cols );


? ? if( type == CV_32FC1 )
? ? ? ? ((float*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
? ? else
? ? {
? ? ? ? assert( type == CV_64FC1 );
? ? ? ? ((double*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
? ? }
}
typedef struct CvMatND
{
? ? int type;
? ? int dims;


? ? int* refcount;
? ? int hdr_refcount;


? ? union
? ? {
? ? ? ? uchar* ptr;
? ? ? ? float* fl;
? ? ? ? double* db;
? ? ? ? int* i;
? ? ? ? short* s;
? ? } data;


? ? struct
? ? {
? ? ? ? int size;
? ? ? ? int step;
? ? }
? ? dim[CV_MAX_DIM];
}
CvMatND;
/* Basic element of the file storage - scalar or collection: */
typedef struct CvFileNode
{
? ? int tag;
? ? struct CvTypeInfo* info; /* type information
? ? ? ? ? ? (only for user-defined object, for others it is 0) */
? ? union
? ? {
? ? ? ? double f; /* scalar floating-point number */
? ? ? ? int i; ? ?/* scalar integer number */
? ? ? ? CvString str; /* text string */
? ? ? ? CvSeq* seq; /* sequence (ordered collection of file nodes) */
? ? ? ? CvFileNodeHash* map; /* map (collection of named file nodes) */
? ? } data;
}
CvFileNode;




】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇BZOJ 2844 albus就是要第一个出场.. 下一篇SICP 习题 (2.8) 解题总结:区..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)