C ++を使用してOpenCVで画像を回転させる方法は?
OpenCVの組み込み機能を使用して画像を回転させるのは簡単な作業です。画像を回転させるには、「highgui.hpp」および「imgproc.hpp」ヘッダーファイルを使用する必要があります。このプログラムでは、画像の回転を処理する関数をさらに紹介します。
次のプログラムは、C++を使用してOpenCVで画像を回転させる方法です。
例
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
Mat before_rotation = imread("bright.jpg");//loading image to a matrix
namedWindow("BeforeRotation");//Declaring window to show the original image//
imshow("BeforeRotation", before_rotation);//showing the image before rotation//
namedWindow("AfterRotation");//declaring window to show rotated image//
int Rotation = 180;//initialization rotation angle//
createTrackbar("Rotation", "AfterRotation", &Rotation, 360);//creating trackbar//
int Height = before_rotation.rows / 2;//getting middle point of rows//
int Width = before_rotation.cols / 2;//getting middle point of height//
while (true) {
Mat for_Rotation = getRotationMatrix2D(Point(Width, Height), (Rotation - 180), 1);//affine transformation matrix for 2D rotation//
Mat for_Rotated;//declaring a matrix for rotated image
warpAffine(before_rotation, for_Rotated, for_Rotation, before_rotation.size());//applying affine transformation//
imshow("AfterRotation", for_Rotated);//show rotated image//
int termination = waitKey(30);//allow system 30 millisecond time to create the rottion effect//
if (termination == 27){ //terminate if Esc button is pressed//
break;
}
}
return 0;
} 出力
-
C ++を使用してOpenCVで画像をロードして表示するにはどうすればよいですか?
このトピックでは、C++でOpenCVを使用して画像を読み込んで表示する方法を決定します。 OpenCVで画像を読み込んで表示するには、次の機能が必要です。 マット: マットは機能ではありません。これはデータ構造であり、変数の一種です。 C ++のint、char、string変数タイプと同様に、MatはOpenCVの変数であり、その中に画像をロードするためのマトリックスデータ構造を作成します。このプログラムでは、「MatmyImage;」と書きました。 これは、myImageという名前の行列変数を宣言していることを意味します。 namedWindow(): メモリを割り当て、画像を
-
Javaを使用してOpenCVで画像を回転させる方法は?
warpAffine() Imgprocクラスのメソッドは、指定された画像にアフィン変換を適用します。このメソッドは-を受け入れます ソース、宛先、および変換マトリックスを表す3つのMatオブジェクト。 出力画像のサイズを表す整数値。 画像を回転するには回転行列を作成し、それを変換行列として他のパラメーターと一緒にこのメソッドに渡します。 例 import java.awt.Image; import java.awt.image.BufferedImage; import java.io.IOException; import javafx.application.Appl