Java OpenCV画像回転90、-90、180



Java Opencv Image Rotation 90



記事のディレクトリ

参照リンク:

https://blog.csdn.net/andylanzhiyong/article/details/84857915
https://blog.csdn.net/guduruyu/article/details/68942211
https://blog.csdn.net/fengbingchun/article/details/52550460

1.画像の反転

関数の説明

Core.flip(Mat src, Mat dst, int flipCode) src: original image dst: target map flipCode: >0: Flip along the y axis, 0: Flip along the x axis, <0: The x and y axes are flipped at the same time(Rotate 180)

x、y軸の説明

画像



テストコード

public static void main(String[] args) { System.load('D:\opencv-320\opencv_java320.dll') Mat src = Imgcodecs.imread('F:\opencvPhoto\test3\test.jpg') Mat dst1 = new Mat() Core.flip(src, dst1, -1) // <0: The x and y axes are flipped at the same time(Rotate 180) Imgcodecs.imwrite('F:\opencvPhoto\test3\flipCode-1.jpg', dst1) Mat dst2 = new Mat() Core.flip(src, dst2, 0) // 0: flip along the x axis Imgcodecs.imwrite('F:\opencvPhoto\test3\flipCode0.jpg', dst2) Mat dst3 = new Mat() Core.flip(src, dst3, 1) // >0: Flip along the y axis Imgcodecs.imwrite('F:\opencvPhoto\test3\flipCode1.jpg', dst3) }

結果の説明

画像

2.画像​​の転置

OpenCVの転置関数は画像の転置を実現します。式は次のとおりです。dst(i、j)= src(j、i)



テストコード

public static void main(String[] args) { System.load('D:\opencv-320\opencv_java320.dll') Mat src = Imgcodecs.imread('F:\opencvPhoto\test3\test.jpg') Mat dst = new Mat() Core.transpose(src, dst) Imgcodecs.imwrite('F:\opencvPhoto\test3\transpose.jpg', dst) }

結果の説明

効果は90度回転してからミラーリングすることです
画像

3.画像の回転90、-90、180

90回転

転置(src、tmp)+フリップ(tmp、dst、1)

public static void main(String[] args) { System.load('D:\opencv-320\opencv_java320.dll') Mat src = Imgcodecs.imread('F:\opencvPhoto\test3\test.jpg') Mat transpose = new Mat() Core.transpose(src, transpose) Mat flip = new Mat() Core.flip(transpose, flip, 1) Imgcodecs.imwrite('F:\opencvPhoto\test3\flip.jpg', flip) }

画像



-90回転

転置(src、tmp)+フリップ(tmp、dst、0)

public static void main(String[] args) { System.load('D:\opencv-320\opencv_java320.dll') Mat src = Imgcodecs.imread('F:\opencvPhoto\test3\test.jpg') Mat transpose = new Mat() Core.transpose(src, transpose) Mat flip = new Mat() Core.flip(transpose, flip, 0) Imgcodecs.imwrite('F:\opencvPhoto\test3\flip.jpg', flip) }

画像

180回転

フリップ(src、dst、-1)

public static void main(String[] args) { System.load('D:\opencv-320\opencv_java320.dll') Mat src = Imgcodecs.imread('F:\opencvPhoto\test3\test.jpg') Mat flip = new Mat() Core.flip(src, flip, -1) Imgcodecs.imwrite('F:\opencvPhoto\test3\flip.jpg', flip) }

画像