Python
 Computer >> コンピューター >  >> プログラミング >> Python

OpenCVを使用して画像に楕円を描画します


このプログラムでは、OpenCVライブラリを使用して画像に楕円を描画します。同じようにOpenCV関数ellipse()を使用します。

元の画像

OpenCVを使用して画像に楕円を描画します

アルゴリズム

Step 1: Import cv2.
Step 2: Read the image using imread().
Step 3: Set the center coordinates.
Step 4: Set the axes length.
Step 5: Set the angle.
Step 6: Set start and end angle.
Step 6: Set the color.
Step 7: Set the thickness.
Step 8: Draw the ellipse by passing the above parameters in the cv2.ellipse function along with the original image.
Step 9: Display the final output.
>

サンプルコード

import cv2
image = cv2.imread('testimage.jpg')
center_coordinates = (120, 100)

axesLength = (100, 50)
angle = 0
startAngle = 0
endAngle = 360
color = (0, 0, 255)
thickness = 5
image = cv2.ellipse(image, center_coordinates, axesLength, angle, startAngle, endAngle, color, thickness)

cv2.imshow('Ellipse', image)

出力

OpenCVを使用して画像に楕円を描画します


  1. PythonでOpenCVを使用して画像内の円を検索する

    OpenCVプラットフォームは、Python用のcv2ライブラリを提供します。これは、コンピュータビジョンで役立つさまざまな形状分析に使用できます。この記事では、OpenCVを使用して円の形状を識別します。そのために、cv2.HoughCircles()関数を使用します。ハフ変換を使用してグレースケール画像内の円を検索します。以下の例では、入力として画像を取得します。次に、そのコピーを作成し、この変換関数を適用して、出力内の円を識別します。 構文 cv2.HoughCircles(image, method, dp, minDist) Where Image is the image file

  2. PythonでOpenCVを使用して輪郭を検索して描画する

    画像分析の目的で、Opencv(Open Source Computer Vision Library)pythonライブラリを使用します。 opencvのインストール後にインポートする必要のあるライブラリ名はcv2です。 以下の例では、画像ファイルに存在する輪郭を見つけます。輪郭は、画像に存在する形状を識別するのに役立ちます。等高線は、同じ強度を持つ画像の境界に沿ったすべての点を結ぶ線として定義されます。 OPenCVのfindContours関数は、輪郭を識別するのに役立ちます。同様に、drawContours関数は、輪郭を描画するのに役立ちます。以下は両方の構文です。 構文 cv.Fi