Cxcore绘图函数
繪圖函數作用于任何象素深度的矩陣/圖像. Antialiasing技術只能在8位圖像上實現.所有的函數包括彩色圖像的色彩參數(色彩參數是指rgb它是由宏CV_RGB或cvScalar函數構成。)和灰度圖像的亮度。
如果一幅繪制圖形部分或全部位于圖像之外,那么對它先做裁剪。 對于彩色圖像正常的色彩通道是B(藍),G(綠),R(紅)..。如果需要其它的色彩,可以通過cvScalar中的特殊色彩通道構造色彩,或者在繪制圖像之前或之后 使用 cvCvtColor或者cvTransform來轉換。
目錄[隱藏]
|
[編輯]
曲線與形狀
[編輯]CV_RGB
創建一個色彩值.
#define CV_RGB( r, g, b ) cvScalar( (b), (g), (r) ) [編輯]Line
繪制連接兩個點的線段
void cvLine( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color,int thickness=1, int line_type=8, int shift=0 ); img函數cvLine 在圖像中的點1和點2之間畫一條線段。線段被圖像或感興趣的矩形(ROI rectangle)所裁剪。對于具有整數坐標的non-antialiasing 線條,使用8-連接或者4-連接Bresenham 算法。畫粗線條時結尾是圓形的。畫 antialiased 線條使用高斯濾波。要指定線段顏色,用戶可以使用使用宏CV_RGB( r, g, b )。
[編輯]Rectangle
繪制簡單、指定粗細或者帶填充的 矩形
void cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color,int thickness=1, int line_type=8, int shift=0 ); img函數 cvRectangle 通過對角線上的兩個頂點繪制矩形。
[編輯]Circle
繪制圓形。
void cvCircle( CvArr* img, CvPoint center, int radius, CvScalar color,int thickness=1, int line_type=8, int shift=0 ); img函數cvCircle繪制或填充一個給定圓心和半徑的圓。圓被感興趣矩形所裁剪。 若指定圓的顏色,可以使用宏 CV_RGB ( r, g, b )。
[編輯]Ellipse
繪制橢圓圓弧和橢圓扇形。
void cvEllipse( CvArr* img, CvPoint center, CvSize axes, double angle,double start_angle, double end_angle, CvScalar color,int thickness=1, int line_type=8, int shift=0 ); img函數cvEllipse用來繪制或者填充一個簡單的橢圓弧或橢圓扇形。圓弧被ROI矩形所忽略。反走樣弧線和粗弧線使用線性分段近似值。所有的角都是以角度的形式給定的。下面的圖片將解釋這些參數的含義。
Parameters of Elliptic Arc
[編輯]
EllipseBox
使用一種簡單的方式來繪制橢圓圓弧和橢圓扇形。
void cvEllipseBox( CvArr* img, CvBox2D box, CvScalar color,int thickness=1, int line_type=8, int shift=0 ); imgThe function cvEllipseBox draws a simple or thick ellipse outline, or fills an ellipse. The functions provides a convenient way to draw an ellipse approximating some shape; that is what cvCamShift and cvFitEllipse do. The ellipse drawn is clipped by ROI rectangle. A piecewise-linear approximation is used for antialiased arcs and thick arcs.
[編輯]FillPoly
填充多邊形內部
void cvFillPoly( CvArr* img, CvPoint** pts, int* npts, int contours,CvScalar color, int line_type=8, int shift=0 ); img函數cvFillPoly用于一個單獨被多邊形輪廓所限定的區域內進行填充。函數可以填充復雜的區域,例如,有漏洞的區域和有交叉點的區域等等。
[編輯]FillConvexPoly
填充凸多邊形
void cvFillConvexPoly( CvArr* img, CvPoint* pts, int npts,CvScalar color, int line_type=8, int shift=0 ); img
函數cvFillConvexPoly填充凸多邊形內部。這個函數比函數cvFillPoly 更快。它除了可以填充凸多邊形區域還可以填充任何的單調多邊形。例如:一個被水平線(掃描線)至多兩次截斷的多邊形。
[編輯]PolyLine
繪制簡單線段或折線。
void cvPolyLine( CvArr* img, CvPoint** pts, int* npts, int contours, int is_closed,CvScalar color, int thickness=1, int line_type=8, int shift=0 ); img函數cvPolyLine 繪制一個簡單直線或折線。
[編輯]文本
[編輯]InitFont
初始化字體結構體。
void cvInitFont( CvFont* font, int font_face, double hscale,double vscale, double shear=0,int thickness=1, int line_type=8 ); font函數cvInitFont初始化字體結構體,字體結構體可以被傳遞到文字顯示函數中。
[編輯]PutText
在圖像中顯示文本字符串。
void cvPutText( CvArr* img, const char* text, CvPoint org, const CvFont* font, CvScalar color ); img函數cvPutText將具有指定字體的和指定顏色的文本加載到圖像中。加載到圖像中的文本被感興趣的矩形框(ROI rectangle)剪切。不屬于指定字體庫的字符用矩形字符替代顯示。
[編輯]GetTextSize
獲得字符串的寬度和高度。
void cvGetTextSize( const char* text_string, const CvFont* font, CvSize* text_size, int* baseline ); font函數cvGetTextSize是用于在指定字體時計算字符串的綁定區域(binding rectangle)。
[編輯]點集和輪廓
[編輯]DrawContours
在圖像中繪制外部和內部的輪廓。
void cvDrawContours( CvArr *img, CvSeq* contour,CvScalar external_color, CvScalar hole_color,int max_level, int thickness=1,int line_type=8, CvPoint offset=cvPoint(0,0) ); img繪制輪廓的最大等級。如果等級為0,繪制單獨的輪廓。如果為1,繪制輪廓及在其后的相同的級別下輪廓。如果值為2,所有的輪廓。如果等級為2,繪制所有同級輪廓及所有低一級輪廓,諸此種種。如果值為負數,函數不繪制同級輪廓,但會升序繪制直到級別為abs(max_level)-1的子輪廓。
thickness當thickness>=0,函數cvDrawContours在圖像中繪制輪廓,或者當thickness<0時,填充輪廓所限制的區域。
#include "cv.h" #include "highgui.h"int main( int argc, char** argv ) {IplImage* src;// 第一條命令行參數確定了圖像的文件名。if( argc == 2 && (src=cvLoadImage(argv[1], 0))!= 0){IplImage* dst = cvCreateImage( cvGetSize(src), 8, 3 );CvMemStorage* storage = cvCreateMemStorage(0);CvSeq* contour = 0;cvThreshold( src, src, 1, 255, CV_THRESH_BINARY );cvNamedWindow( "Source", 1 );cvShowImage( "Source", src );cvFindContours( src, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );cvZero( dst );for(?; contour?!= 0; contour = contour->h_next ){CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );/* 用1替代 CV_FILLED 所指示的輪廓外形 */cvDrawContours( dst, contour, color, color, -1, CV_FILLED, 8 );}cvNamedWindow( "Components", 1 );cvShowImage( "Components", dst );cvWaitKey(0);} }在樣本中用1替代 CV_FILLED 以指示的得到外形。
(注意:在cvFindContours中參數為CV_CHAIN_CODE時,cvDrawContours用CV_FILLED時不會畫出任何圖形)
[編輯]InitLineIterator
初始化直線迭代器
int cvInitLineIterator( const CvArr* image, CvPoint pt1, CvPoint pt2,CvLineIterator* line_iterator, int connectivity=8,int left_to_right=0 ); img函數cvInitLineIterator初始化直線迭代器并返回兩個端點間點的數目。兩個端點都必須在圖像內部。在迭代器初始化以后,所有的在連接兩個終點的柵欄線上的點,可以通過訪問CV_NEXT_LINE_POINT點的方式獲得。在線上的這些點使用4-鄰接或者8-鄰接的Bresenham算法計算得到。
例:使用直線迭代來計算沿著彩色線上的點的像素值。
CvScalar sum_line_pixels( IplImage* image, CvPoint pt1, CvPoint pt2 ){CvLineIterator iterator;int blue_sum = 0, green_sum = 0, red_sum = 0;int count = cvInitLineIterator( image, pt1, pt2, &iterator, 8, 0 );for( int i = 0; i < count; i++ ){blue_sum += iterator.ptr[0];green_sum += iterator.ptr[1];red_sum += iterator.ptr[2];CV_NEXT_LINE_POINT(iterator);/* print the pixel coordinates: demonstrates how to calculate the coordinates */{int offset, x, y;/* assume that ROI is not set, otherwise need to take it into account. */offset = iterator.ptr - (uchar*)(image->imageData);y = offset/image->widthStep;x = (offset - y*image->widthStep)/(3*sizeof(uchar) /* size of pixel */);printf("(%d,%d)/n", x, y );}}return cvScalar( blue_sum, green_sum, red_sum );} [編輯]ClipLine
剪切圖像矩形區域內部的直線。
int cvClipLine( CvSize img_size, CvPoint* pt1, CvPoint* pt2 ); img_size函數cvClipLine計算線段完全在圖像中的一部分。如果線段完全在圖像中,返回0,否則返回1。
[編輯]Ellipse2Poly
用折線逼近橢圓弧
int cvEllipse2Poly( CvPoint center, CvSize axes,int angle, int arc_start,int arc_end, CvPoint* pts, int delta ); center函數cvEllipse2Poly計算給定的橢圓弧的逼近折線的頂點,被cvEllipse使用。
取自"http://www.opencv.org.cn/index.php/Cxcore%E7%BB%98%E5%9B%BE%E5%87%BD%E6%95%B0"總結
以上是生活随笔為你收集整理的Cxcore绘图函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 震惊!被这样开发的P2P分发下载技术
- 下一篇: 下班前10分钟光速安装skywalkin