OpenCV基础数据结构

来源:互联网 发布:网上报名软件 编辑:程序博客网 时间:2024/06/11 13:36

数据结构是程序设计的基础。OpenCV基础数据结构包括点,矩形框设计类型,矩阵,不确定数组,图像头等

1.二位整形坐标点:CvPoint

typedef struct CvPoint{int x;   //x坐标,通常以0为基点int y;   //y坐标,通常以0为基点}CvPoint;inline CvPoint cvPoint(int x,int y);inline CvPoint cvPointFrom32f(CvPoint2D32f point);
2、二位浮点型坐标点


typedef struct CvPoint2D32f{    float x;    float y;}CvPoint2D32f;inline CvPoint2D32f cvPoint2D32f(double x,double y);inline CvPoint2D32f cvPointTo32f(CvPoint point);

3.三位浮点型坐标

typedef struct CvPoint3D32f{    float x;    float y;    float z;}CvPoint3D32f;inline CvPoint2D32f cvPoint2D32f(double x,double y,double z);
4,矩形框大小(像素精度)

typedef struct CvSize{    int width;    int height;}CvSize;inline CvSize cvSize(int width,int height);

5,矩形框大小(亚像素精度)

typedef struct CvSize2D32f{    float width;    float height;}CvSize2D32f;inline CvSize2D32f  cvSize2D32f( double width, double height ){    CvSize2D32f s;    s.width = (float)width;    s.height = (float)height;    return s;}

6,矩形框

typedef struct CvRect{    int x;    int y;    int width;    int height;}CvRect;inline  CvRect  cvRect( int x, int y, int width, int height ){    CvRect r;    r.x = x;    r.y = y;    r.width = width;    r.height = height;    return r;}

7,数据容器

typedef struct CvScalar{    double val[4];}CvScalar;CV_INLINE  CvScalar  cvScalar( double val0, double val1 CV_DEFAULT(0),                               double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0)){    CvScalar scalar;    scalar.val[0] = val0; scalar.val[1] = val1;    scalar.val[2] = val2; scalar.val[3] = val3;    return scalar;}CV_INLINE  CvScalar  cvRealScalar( double val0 ){    CvScalar scalar;    scalar.val[0] = val0;    scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;    return scalar;}CV_INLINE  CvScalar  cvScalarAll( double val0123 ){    CvScalar scalar;    scalar.val[0] = val0123;    scalar.val[1] = val0123;    scalar.val[2] = val0123;    scalar.val[3] = val0123;    return scalar;}

8,迭代算法的终止准则

#define CV_TERMCRIT_ITER    1#define CV_TERMCRIT_NUMBER  CV_TERMCRIT_ITER#define CV_TERMCRIT_EPS     2typedef struct CvTermCriteria{    int    type;  /* may be combination of                     CV_TERMCRIT_ITER                     CV_TERMCRIT_EPS */    int    max_iter;    double epsilon;}CvTermCriteria;CV_INLINE  CvTermCriteria  cvTermCriteria( int type, int max_iter, double epsilon ){    CvTermCriteria t;    t.type = type;    t.max_iter = max_iter;    t.epsilon = (float)epsilon;    return t;}

9,多通道矩阵

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;

10,多维,多通道密集数组

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;

11,多维,多通道稀疏数组

typedef struct CvSparseMat{    int type;    int dims;    int* refcount;    int hdr_refcount;    struct CvSet* heap;    void** hashtable;    int hashsize;    int valoffset;    int idxoffset;    int size[CV_MAX_DIM];}CvSparseMat;

12,图像头

typedef struct _IplImage{    int  nSize;             /* sizeof(IplImage) */    int  ID;                /* version (=0)*/    int  nChannels;         /* Most of OpenCV functions support 1,2,3 or 4 channels */    int  alphaChannel;      /* Ignored by OpenCV */    int  depth;             /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,                               IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported.  */    char colorModel[4];     /* Ignored by OpenCV */    char channelSeq[4];     /* ditto */    int  dataOrder;         /* 0 - interleaved color channels, 1 - separate color channels.                               cvCreateImage can only create interleaved images */    int  origin;            /* 0 - top-left origin,                               1 - bottom-left origin (Windows bitmaps style).  */    int  align;             /* Alignment of image rows (4 or 8).                               OpenCV ignores it and uses widthStep instead.    */    int  width;             /* Image width in pixels.                           */    int  height;            /* Image height in pixels.                          */    struct _IplROI *roi;    /* Image ROI. If NULL, the whole image is selected. */    struct _IplImage *maskROI;      /* Must be NULL. */    void  *imageId;                 /* "           " */    struct _IplTileInfo *tileInfo;  /* "           " */    int  imageSize;         /* Image data size in bytes                               (==image->height*image->widthStep                               in case of interleaved data)*/    char *imageData;        /* Pointer to aligned image data.         */    int  widthStep;         /* Size of aligned image row in bytes.    */    int  BorderMode[4];     /* Ignored by OpenCV.                     */    int  BorderConst[4];    /* Ditto.                                 */    char *imageDataOrigin;  /* Pointer to very origin of image data                               (not necessarily aligned) -                               needed for correct deallocation */}IplImage;



0 0