พลิก() วิธีการของ Core คลาสของ OpenCV พลิกรูปภาพตามแนวแกน x/y วิธีนี้ยอมรับ -
-
เมทริกซ์ต้นทางที่รวมข้อมูลของภาพต้นฉบับ
-
เมทริกซ์ปลายทางว่างเพื่อเก็บข้อมูลของภาพที่ได้ผลลัพธ์
-
โค้ดพลิกเพื่อระบุทิศทางของภาพ (แกน 0 –x, +ve – แกน y – ve ทั้งสองแกน)
พลิกภาพ −
-
โหลดไลบรารีเนทีฟหลักของ OpenCV โดยใช้เมธอด loadLibrary()
-
อ่านเนื้อหาของไฟล์รูปภาพเป็นเมทริกซ์โดยใช้เมธอด 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");
}
} อินพุต

ผลลัพธ์
