日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

C++?opencv實(shí)現(xiàn)幾何圖形繪制_C 語(yǔ)言

作者:淺念念52 ? 更新時(shí)間: 2022-07-07 編程語(yǔ)言

在學(xué)習(xí)過(guò)程中,我們可以在圖像中繪制一些幾何圖形,比如矩形,橢圓,線段,填充多邊形等,這些函數(shù)都挺容易理解,下面簡(jiǎn)單看一下。

1.矩形 rectangle()

通過(guò)對(duì)角線上的兩個(gè)頂點(diǎn)繪制矩形

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

img 名稱
rec pt1矩形的頂點(diǎn) pt2與pt1相對(duì)的矩形頂點(diǎn)
color 顏色  也可以用像素存放類Scalar
thickness 寬度 如果是-1,就代表對(duì)改矩形進(jìn)行填充
lineType  類型
shift 移位點(diǎn)坐標(biāo)中的小數(shù)位數(shù)。

代碼:

int main()
{
	Mat img = Mat::ones(240, 240, CV_8UC3);
	rectangle(img, Rect(20, 20, 100, 100), Scalar(0, 0, 255),7);
	imshow("www", img);
	waitKey(0);
}

效果圖:

2. 圓 circle()

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

img 名稱
center 圓心坐標(biāo)
radius 圓的半徑
color 圓環(huán)顏色
thickness 正數(shù),則表示圓輪廓的厚度 負(fù)數(shù) 對(duì)該圓填充顏色
lineType  類型
shift  移位中心坐標(biāo)和半徑值的小數(shù)位數(shù)。

代碼:

int main()
{
	Mat img1=Mat::zeros(100, 100, CV_8UC3);
	circle(img1, Point(40, 40), 20, Scalar(0, 0, 255),-1);//-1 填充
	imshow("www", img1);
	waitKey(0);
}

效果圖:

3.橢圓 elliple()

void ellipse(InputOutputArray img, Point center, Size axes,
		double angle, double startAngle, double endAngle,
		const Scalar& color, int thickness = 1,
		int lineType = LINE_8, int shift = 0);

img 名稱
center 橢圓的中心。
axes 軸 橢圓主軸大小的一半。
angle	橢圓旋轉(zhuǎn)角度。
startAngle	橢圓弧的起始角,以度表示。
endAngle	橢圓弧的結(jié)束角,以度數(shù)表示。
color	橢圓顏色。
thickness 正數(shù) 橢圓圓弧輪廓的厚度  負(fù)數(shù) 對(duì)橢圓進(jìn)行填充。
linetype 橢圓邊界類型。 
shift 中心坐標(biāo)和坐標(biāo)軸值的小數(shù)位數(shù)。

代碼:

int main()
{
	Mat img1 = Mat::zeros(300, 300, CV_8UC3);
	ellipse(img1, Point(100, 100), Size(40, 25), 0, 0, 360, Scalar(0, 0, 255),5);
	imshow("111", img1);
	waitKey(0);
}

效果圖:

原文鏈接:https://blog.csdn.net/Lightismore/article/details/123734985

欄目分類
最近更新