- OpenCV 教程
- OpenCV - 首頁
- OpenCV - 概述
- OpenCV - 環境配置
- OpenCV - 影像儲存
- OpenCV - 讀取影像
- OpenCV - 寫入影像
- OpenCV - 圖形使用者介面 (GUI)
- 繪圖函式
- OpenCV - 繪製圓形
- OpenCV - 繪製直線
- OpenCV - 繪製矩形
- OpenCV - 繪製橢圓
- OpenCV - 繪製多邊形
- OpenCV - 繪製凸多邊形
- OpenCV - 繪製帶箭頭的直線
- OpenCV - 新增文字
- 濾波
- OpenCV - 雙邊濾波
- OpenCV - 方框濾波
- OpenCV - 平方盒濾波
- OpenCV - Filter2D
- OpenCV - 膨脹
- OpenCV - 腐蝕
- OpenCV - 形態學操作
- OpenCV - 影像金字塔
- Sobel 導數
- OpenCV - Sobel 運算元
- OpenCV - Scharr 運算元
- 攝像頭和人臉檢測
- OpenCV - 使用攝像頭
- OpenCV - 圖片中的人臉檢測
- 使用攝像頭進行人臉檢測
- OpenCV 有用資源
- OpenCV - 快速指南
- OpenCV - 有用資源
- OpenCV - 討論
OpenCV - 寫入影像
OpenCV 的 `Imgcodecs` 類中的 `write()` 方法用於寫入影像。要寫入影像,請重複上一個示例中的前三個步驟。
要寫入影像,您需要呼叫 `Imgcodecs` 類的 `imwrite()` 方法。
以下是此方法的語法。
imwrite(filename, mat)
此方法接受以下引數:
**filename** - 一個表示儲存檔案路徑的 **String** 變數。
**mat** - 一個表示要寫入影像的 **Mat** 物件。
示例
下面的程式是使用 Java 程式和 OpenCV 庫 **寫入影像** 的示例。
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
public class WritingImages {
public static void main(String args[]) {
//Loading the OpenCV core library
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//Instantiating the imagecodecs class
Imgcodecs imageCodecs = new Imgcodecs();
//Reading the Image from the file and storing it in to a Matrix object
String file ="C:/EXAMPLES/OpenCV/sample.jpg";
Mat matrix = imageCodecs.imread(file);
System.out.println("Image Loaded ..........");
String file2 = "C:/EXAMPLES/OpenCV/sample_resaved.jpg";
//Writing the image
imageCodecs.imwrite(file2, matrix);
System.out.println("Image Saved ............");
}
}
執行上述程式後,您將獲得以下輸出:
Image Loaded .......... Image Saved ...........
如果您開啟指定的路徑,您可以觀察到如下所示的已儲存影像:
廣告