C ++を使用してOpenCVで線を引く方法は?
線を引くには、始点と終点の2つの点が必要です。線を引くためのキャンバスも必要です。
キャンバスのマトリックスであるOpenCVを使用して、ラインの開始点と終了点を定義する必要があります。線にも色を付ける必要があります。線の太さも説明する必要があります。 OpenCVを使用して線を描画する場合は、マトリックス、2つのポイント、および色と線の太さを宣言する必要があります。
OpenCVを使用するには、
このメソッドの基本的な構文は次のとおりです-
構文
line(whiteMatrix, starting, ending, 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 starting(50, 50);//Starting Point of the line
Point ending(150, 150);//Ending Point of the line
Scalar line_Color(0, 0, 0);//Color of the line
int thickness = 2;//thickens of the line
namedWindow("GrayImage");//Declaring a window to show the line
line(whiteMatrix, starting, ending, line_Color, thickness);//using line() function to draw the line//
imshow("GrayImage", whiteMatrix);//showing the line//
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関数line()を使用して画像に単純な線を描画します。 元の画像 アルゴリズム Step 1: Import cv2. Step 2: Read the image using imread(). Step 3: Get the dimensions of the image using the image.shape method. Step 4: Define starting point of the line. Step 5: Define the end point of the line. Step 6: Define the thicknes