OpenCV學習(2)--基本資料結構

來源:互聯網
上載者:User

標籤:style   blog   color   資料   width   div   

OpenCV的基本資料結構

CvPoint:表示映像中的點

CvPoint2D32f:二維空間中的點

CvPoint3D32f:三維空間中的點

這些都是結構體,並不是C++語言中的類,所以他們的建構函式就是簡單的內嵌函式。

 1 typedef struct CvPoint 2 { 3     int x; 4     int y; 5 } 6 CvPoint; 7  8  9 CV_INLINE  CvPoint  cvPoint( int x, int y )10 {11     CvPoint p;12 13     p.x = x;14     p.y = y;15 16     return p;17 }

其中的CV_INLINE就是一個宏定義:

1 define CV_INLINE inline

CvSize:表示映像的尺寸

CvSize2D32f:浮點型資料表示映像的尺寸

 1 typedef struct CvSize 2 { 3     int width; 4     int height; 5 } 6 CvSize; 7  8 CV_INLINE  CvSize  cvSize( int width, int height ) 9 {10     CvSize s;11 12     s.width = width;13     s.height = height;14 15     return s;16 }

CvRect表示映像的部分地區

 1 typedef struct CvRect 2 { 3     int x; 4     int y; 5     int width; 6     int height; 7 } 8 CvRect; 9 10 CV_INLINE  CvRect  cvRect( int x, int y, int width, int height )11 {12     CvRect r;13 14     r.x = x;15     r.y = y;16     r.width = width;17     r.height = height;18 19     return r;20 }

CvScalar包含4個浮點型的成員,可以用來表示B、G、R、alpha。它有三個建構函式,具體的定義:


typedef struct CvScalar
{
double val[4];
}
CvScalar;


//至少傳一個參數,如果後面三個沒有,預設為0
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;
}


//只對第一個參數賦值,後面的為0
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;
}


CvArr、CvMat和IplImage關係

派生關係為:CvArr-->CvMat-->IplImage,當CvArr用作函數的參數的時候,無論傳入的是CvMat還是IplImage,內部都是按CvMat處理。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.