opencv的core类的flip()方法可以沿着x/y轴翻转图像。该方法接受以下参数:
源矩阵,包含原始图像的数据。
一个空的目标矩阵,用于保存结果图像的数据。
一个翻转代码,用于指定图像的方向(0表示沿x轴翻转,正数表示沿y轴翻转,负数表示同时沿两个轴翻转)。
要翻转图像,可以按照以下步骤进行:
立即学习“Java免费学习笔记(深入)”;
使用loadLibrary()方法加载OpenCV核心本地库。
使用imread()方法将图像文件的内容读取到矩阵中。
创建一个空矩阵来保存结果。
通过传递上述创建的矩阵调用flip()方法。
使用imwrite()方法创建图像,将目标矩阵作为参数传递。
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
public class ChangingOrientation {
public static void main(String args[]) {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//Reading the Image from the file and storing it in to a Matrix object
String file ="D:\Images\cat.jpg";
Mat src = Imgcodecs.imread(file);
//Creating an empty matrix to store the result
Mat dst = new Mat();
//Changing the orientation of an image
Core.flip(src, dst, -1);
//Writing the image
Imgcodecs.imwrite("D:\Images\flipping.jpg", dst);
System.out.println("Image Processed");
}
}

以上就是如何使用Java OpenCV库翻转图像?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号