如何使用 Java OpenCV 库翻转图像?
OpenCV Core 类的flip()方法沿 x/y 轴翻转图像。此方法接受 −
包含原始图像数据的源矩阵。
用于保存结果图像数据的空目标矩阵。
翻转代码,用于指定图像的方向(0 –x 轴,+ve – y 轴,– ve 两条轴)。
若要翻转图像 −
使用 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
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP