Python 用 OpenCV 畫橢圓 5

2021-08-31 19:10:31 字數 2388 閱讀 8542

利用 opencv 自帶的ellipse() 函式畫橢圓並顯示,其函式宣告如下:

cv2.ellipse(img, center, axes, rotateangle, startangle, endangle, color[

, thickness[

, linetype[

, shift]]]

)

shift:座標點小數點位數

畫橢圓的完整**如下:

#!/usr/bin/python

# -*- coding: utf-8 -*-

"""@time : 2018-11-13 21:20

@author : jianjun.wang

@email : [email protected]

"""import numpy as np

import cv2 as cv

img = np.zeros(

(320

,320,3

), np.uint8)

#生成乙個空灰度影象

print img.shape # 輸出:(320, 320, 3)

# 繪製乙個紅色橢圓

ptcenter =

(160

,160

)# 中心點位置

axessize =

(100,45

)# 長軸半徑為 90,短軸半徑為 60

rotateangle =

90# 旋轉角度為 90

startangle =

0endangle =

360point_color =(0

,0,255

)# bgr

thickness =

1 linetype =

4cv.ellipse(img, ptcenter, axessize, rotateangle, startangle, endangle, point_color, thickness, linetype)

# 繪製乙個綠色橢圓

ptcenter =

(160

,160

)# 中心點位置

axessize =(90

,60)# 長軸半徑為 90,短軸半徑為 60

rotateangle =

0# 旋轉角度為 0

startangle =

0endangle =

360point_color =(0

,255,0

)# bgr

thickness =

1 linetype =

4cv.ellipse(img, ptcenter, axessize, rotateangle, startangle, endangle, point_color, thickness, linetype)

# 繪製乙個藍色上半橢圓

ptcenter =

(160,60

)# 中心點位置

axessize =

(100,45

)# 長軸半徑為 90,短軸半徑為 60

rotateangle =

0# 旋轉角度為 90

startangle =

180endangle =

360point_color =

(255,0

,0)# bgr

thickness =

1 linetype =

4cv.ellipse(img, ptcenter, axessize, rotateangle, startangle, endangle, point_color, thickness, linetype)

cv.namedwindow(

"alanwang"

)cv.imshow(

'alanwang'

, img)

cv.waitkey (

10000

)# 顯示 10000 ms 即 10s 後消失

cv.destroyallwindows(

)

執行後效果如下:

原文英文文件

python 安裝 opencv 及顯示影象 (1)

python 用 opencv 畫點和圓 (2)

python 用 opencv 畫直線 (3)

python 用 opencv 畫矩形 (4)

python 用 opencv 畫橢圓 (5)

python 用 opencv 顯示文字 (6)

python畫橢圓 Python 如何繪製橢圓?

在畫圖作業中遇到這個問題,總結一下 通常怎麼在python中畫圖?資料的處理 分析和視覺化已經成為 python 近年來最重要的應用之一。python 在資料視覺化方面擁有很多功能強大的工具,matplotlib就是其中的乙個佼佼者。這是 python 在科學領域中迅速發展的乙個主要原因。簡單來說,...

用python畫樹林 用python畫櫻樹

from turtle import from random import from math import def tree n,l pd 下筆 陰影效果 t cos radians heading 45 8 0.25 pencolor t,t,t pensize n 3 forward l 畫樹...

用Python畫笑臉

開心一下,喵 很早之前畫的,放上來做個紀念吧 如下 from turtle import screensize 600,600 speed 10 def arc initial degree,step,rotate,rangenum seth initial degree for i in rang...