C ++を使用してOpenCVで画像のサイズを変更し、境界線を追加するにはどうすればよいですか?
このトピックでは、トラックバーの別のアプリケーションを紹介します。ここでは、トラックバーを使用して画像のサイズを変更し、画像に境界線を追加し、トラックバーを使用して境界線のサイズを変更します。
次のプログラムを使用して、画像のサイズの変更、境界線の追加、境界線のサイズの変更、および画像の回転を行うことができます。前の例と似ています。
次のプログラムは、同じトラックバーに複数のスライダーを追加する方法を示しています。
例
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int Rotate = 180;//initializing angle//
int Scale = 50;//initializing scale//
int Border = 0;//initial Border//
Mat before_Rotate;//declaring matrix for before rotation//
int vertical = 0;//initial vertical value//
int horizontal = 0;//initial horizontal value//
void rotator(int, void*){ //function to rotate image//
Mat Rotation = getRotationMatrix2D(Point(horizontal, vertical),(Rotate - 180), Scale / 50.0);//affine transformation matrix for 2D rotation//
Mat Rotated;//matrix for rotated image
warpAffine(before_Rotate, Rotated, Rotation, before_Rotate.size(), INTER_LINEAR, Border, Scalar());//applying affine transformation//
imshow("RotatedImage", Rotated);//show rotated image//
}
int main(int argc,char**argv) {
before_Rotate = imread("sky.jpg");//loading image in the matrix//
vertical = before_Rotate.rows / 2;//getting midpoint of vertical pixels//
horizontal = before_Rotate.cols / 2;//getting midpoints of horizontal pixels//
namedWindow("BeforeRotate");//declaring window to show image before rotation//
imshow("BeforeRotate", before_Rotate);//showing image before rotation//
namedWindow("AfterRotate");//declaring window to show image after rotation//
createTrackbar("Angle", "AfterRotate", &Rotate, 360, rotator);//creating trackbar for rotation//
createTrackbar("Scale", "AfterRotate", &Scale, 100, rotator);//creating trackbar to change size//
createTrackbar("Border Mode", "After Rotate", &Border, 5, rotator);//creating trackbar to add border//
int cbfunction = 0;//initiate value of rotator function's argument//
rotator(cbfunction, &cbfunction);//call back rotator function//
waitKey(0);//wait till keystroke//
return 0;
} 出力
-
C ++を使用してOpenCVの画像のチャンネル数を計算するにはどうすればよいですか?
このトピックでは、画像のチャンネル数を確認する方法を理解します。プログラムを実行すると、チャンネル番号がコンソールウィンドウに表示されます。 チャネルの番号を取得するために、channels()という名前のOpenCVのクラスを使用しました。 クラスchannels()のオブジェクトとして画像マトリックスを渡すと、チャネルに整数値が与えられます。 次のプログラムは、チャネルの数をカウントし、コンソールウィンドウに表示します。 例 #include<iostream> #include<opencv2/highgui/highgui.hpp> using namesp
-
C ++を使用してOpenCVで画像をロードして表示するにはどうすればよいですか?
このトピックでは、C++でOpenCVを使用して画像を読み込んで表示する方法を決定します。 OpenCVで画像を読み込んで表示するには、次の機能が必要です。 マット: マットは機能ではありません。これはデータ構造であり、変数の一種です。 C ++のint、char、string変数タイプと同様に、MatはOpenCVの変数であり、その中に画像をロードするためのマトリックスデータ構造を作成します。このプログラムでは、「MatmyImage;」と書きました。 これは、myImageという名前の行列変数を宣言していることを意味します。 namedWindow(): メモリを割り当て、画像を