OpenCV-Pythonは、コンピュータービジョンの問題を解決するために設計されたPythonバインディングライブラリです。cv2.ellipse()
この方法は、任意の画像に楕円を描くために使用されます。
cv2.ellipse(image, centerCoordinates, axesLength, angle, startAngle, endAngle, color [, thickness[, lineType[, shift]]])
パラメータ:
- image:楕円が描かれる画像です。
- centerCoordinates:楕円の中心座標です。座標は、(X座標値、Y座標値)の2つの値のタプルとして表されます。
- axisLength:楕円の長軸と短軸(長軸の長さ、短軸の長さ)を含む2つの変数のタプルが含まれています。
- 角度:楕円の回転角(度単位)。
- startAngle:楕円弧の開始角度(度単位)。
- endAngle:楕円弧の終了角度(度単位)。
- color:描画する形状の境界線の色です。BGR、我々はタプルを渡します。例:(255、0、0)は青です。
- 厚さ:ピクセル単位の形状の境界線の厚さです。厚さ-1ピクセルは、指定された色で形状を塗りつぶします。
- lineType:これはオプションのパラメーターであり、楕円の境界のタイプを指定します。
- shift:これはオプションのパラメーターです。中心座標の小数点以下の桁数と軸の値を表します。
戻り値:画像を返します。
以下のすべての例で使用されている画像:
例1:
# Python program to explain cv2.ellipse() method
# importing cv2
import cv2
# path
path = r'C:\Users\Rajnish\Desktop\geeksforgeeks\geeks.png'
# Reading an image in default mode
image = cv2.imread(path)
# Window name in which image is displayed
window_name = 'Image'
center_coordinates = (120, 100)
axesLength = (100, 50)
angle = 0
startAngle = 0
endAngle = 360
# Red color in BGR
color = (0, 0, 255)
# Line thickness of 5 px
thickness = 5
# Using cv2.ellipse() method
# Draw a ellipse with red line borders of thickness of 5 px
image = cv2.ellipse(image, center_coordinates, axesLength,
angle, startAngle, endAngle, color, thickness)
# Displaying the image
cv2.imshow(window_name, image)
出力:
例2:
-1pxの厚さと30度の回転を使用します。
# Python program to explain cv2.ellipse() method
# importing cv2
import cv2
# path
path = r'C:\Users\Rajnish\Desktop\geeksforgeeks\geeks.png'
# Reading an image in default mode
image = cv2.imread(path)
# Window name in which image is displayed
window_name = 'Image'
center_coordinates = (120, 100)
axesLength = (100, 50)
angle = 30
startAngle = 0
endAngle = 360
# Blue color in BGR
color = (255, 0, 0)
# Line thickness of -1 px
thickness = -1
# Using cv2.ellipse() method
# Draw a ellipse with blue line borders of thickness of -1 px
image = cv2.ellipse(image, center_coordinates, axesLength, angle,
startAngle, endAngle, color, thickness)
# Displaying the image
cv2.imshow(window_name, image)
出力:
Matlab、Python、C ++でプログラミング、機械学習、コンピュータービジョン理論の実装とガイダンス、学部と修士の両方の学位、塩漬け魚の取引、専門家の回答を知ってください。QQ番号757160542に連絡してください。