如何使用 C++ 在 OpenCV 中儲存影像?
這裡,我們將瞭解如何將 OpenCV 影像儲存到計算機的任何位置。 OpenCV 提供 imwrite() 函式,以將影像儲存到指定檔案中。檔案擴充套件名錶示影像格式。
該函式的實際格式為 -
imwrite("Destination/Name of the image with extension", Source Matrix)這裡,“目標”是我們希望儲存影像的位置。在此程式中,我們以“Lakshmi.jpg”的形式儲存影像。我們可以為影像指定任何名稱。“源矩陣”是已載入影像的矩陣。在此程式中,影像載入為“myImage”矩陣。
範例
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main(int argc,const char** argv) {
Mat myImage;//declaring a matrix named myImage//
myImage = imread("lena.png");//loading the image named lena in the matrix//
imwrite("lakshmi.jpg", myImage);
waitKey(0);//wait till user press any key
destroyWindow("MyWindow");//close the window and release allocate memory//
cout << "Image is saved successfully…..";
return 0;
}輸出
Image is saved successfully...
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP