opencv 畫圖

直線

函數

void line(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

參數:

img: 要繪製線段的圖像。
pt1: 線段的起點。
pt2: 線段的終點。
color: 線段的顏色,通過一個Scalar對象定義。
thickness: 線條的寬度。
lineType: 線段的類型。可以取值8,4, 和CV_AA, 分別代表8鄰接連接線,4鄰接連接線和反鋸齒連接線。默認值爲8鄰接。爲了獲得更好地效果可以選用CV_AA(採用了高斯濾波)。
shift: 座標點小數點位數。

Demo

line(src,Point(10,10),Point(200,200),Scalar(0,0,255),5,CV_AA);

矩形

函數

void rectangle(Mat& img, Point pt1,Point pt2,const Scalar& color, int thickness=1, int lineType=8, int shift=0);

void rectangle(Mat& img, Rect rec, const Scalar& color, int thickness=1, int lineType=8, int shift=0 );

參數:

img 圖像。
pt1 矩形的一個頂點。
pt2 矩形對角線上的另一個頂點。
rec 矩形區域(x,y,width,height)。
color 線條顏色 (RGB) 或亮度(灰度圖像 )(grayscale image。
thickness 組成矩形的線條的粗細程度。取負值時(如 CV_FILLED)函數繪製填充了色彩的矩形。
line_type 線條的類型;見cvLine的描述。
shift 座標點的小數點位數。

Demo

rectangle (src, cv::Rect(10,10,50,50), Scalar(0, 0, 255), -1, 8, 0);
rectangle (src, Point(9, 9), Point(61, 61), Scalar(0, 255, 255), 2, 8, 0);

函數

void circle(CV_IN_OUT Mat& img, Point center, int radius, const Scalar& color, int thickness=1, int lineType=8, int shift=0); 

參數:

img 圖像。
center 畫圓的圓心座標。
radius 圓的半徑。
color爲 圓的顏色。
thickness 圓線條的粗細,值越大則線條越粗,爲負數則是填充效果
line_type 線條的類型;見cvLine的描述。
shift 座標點的小數點位數。

Demo

circle(src,Point(100,100),40,CV_RGB(0,0,0),2,8,0);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章