如何使用 C++ 在 OpenCV 中保存图像?
在这里,我们将了解如何将OpenCV图像保存到您计算机上的任何位置。OpenCV提供imwrite()了将图像保存到指定文件的功能。文件扩展名代表图像格式。
该函数的实际格式是-
imwrite("Destination/Name of the image with extension", Source Matrix)
在这里,“目的地”是我们想要保存图像的地方。在这个程序中,我们将图像保存为“Lakshmi.jpg”。我们可以给图像起任何名字。“源矩阵”是图像已加载的矩阵。在这个程序中,图像被加载为“myImage”矩阵。
示例
#include输出结果#include 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);//等到用户按任意键 destroyWindow("MyWindow");//close the window and release allocate memory// cout << "Image is saved successfully….."; return 0; }
Image is saved successfully...