如何使用 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