C ++を使用してOpenCVで楕円を描く方法は?
楕円を描くには、中心、長軸、短軸が必要です。つまり、楕円には3つのパラメータが必要です。楕円を描画するマトリックスが必要であり、線の太さと線の色を宣言する必要があります。
OpenCVを使用して楕円を描画する場合は、回転角について言及する必要があり、2つの追加パラメーターの開始点と終了点があります。 'ellipse()'関数を呼び出すには、
このメソッドの基本的な構文は次のとおりです-
構文
ellipse(whiteMatrix, center, xy,angle, starting_point, ending_point, line_Color,thickness);
次のプログラムは、OpenCVで楕円を描く方法を示しています。
例
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main() {
Mat whiteMatrix(200, 200, CV_8UC3, Scalar(255, 255, 255));//Declaring a white matrix
Point center(100, 100);//Declaring the center point
Size xy(100, 50);//Declaring the major and minor axis of the ellipse//
int angle = 50;//angle of rotation//
int starting_point = 0;//Starting point of the ellipse//
int ending_point = 360;//Ending point of the ellipse//
Scalar line_Color(0, 0, 0);//Color of the Ellipse//
int thickness = 2;//thickens of the line//
namedWindow("whiteMatrix");//Declaring a window to show the ellipse//
ellipse(whiteMatrix, center, xy,angle, starting_point, ending_point, line_Color,thickness);//Drawing the ellipse
imshow("WhiteMatrix", whiteMatrix);//Showing the ellipse
waitKey(0);//Waiting for Keystroke
return 0;
} 出力
-
Javaを使用してOpenCVで線を引く方法は?
Java OpenCVライブラリのorg.opencv.imgprocパッケージには、Imgprocという名前のクラスが含まれています。線を引くには、 line()を呼び出す必要があります このクラスのメソッド。このメソッドは、次のパラメーターを受け入れます- 線を引く画像を表すマットオブジェクト。 線が引かれるポイントを表す2つのPointオブジェクト。 線の色を表すScalarオブジェクト。 (BGR) 線の太さを表す整数(デフォルト:1)。 例 import org.opencv.core.Core; import org.opencv.core.Mat; i
-
OpenCVを使用して画像に楕円を描画します
このプログラムでは、OpenCVライブラリを使用して画像に楕円を描画します。同じようにOpenCV関数ellipse()を使用します。 元の画像 アルゴリズム 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 th