ที่นี่ เราจะเข้าใจวิธีการบันทึกอิมเมจ OpenCV ไปยังตำแหน่งใดๆ บนคอมพิวเตอร์ของคุณ OpenCV ให้ imwrite() ฟังก์ชั่นบันทึกภาพไปยังไฟล์ที่ระบุ นามสกุลไฟล์แสดงถึงรูปแบบภาพ
รูปแบบที่แท้จริงของฟังก์ชันคือ −
imwrite("Destination/Name of the image with extension", Source Matrix) ที่นี่ "ปลายทาง" คือที่ที่เราต้องการบันทึกภาพ ในโปรแกรมนี้ เราบันทึกภาพเป็น "Lakshmi.jpg" เราสามารถตั้งชื่อภาพได้ "Source Matrix" คือเมทริกซ์ที่โหลดรูปภาพ ในโปรแกรมนี้ รูปภาพจะโหลดเป็นเมทริกซ์ "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...