保存图像

实际上,Live Capture 示例适用于捕获图像,因此我使用它捕获图像并将其保存在文件夹中。

#include <fstream>
#include <string>

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main() 
{
    std::stringstream file; // to write the file name 
    
    cv::VideoCapture cap(0); // create a capture object

    int counter = 0; // Create counter
    
    while(true) // infinite loop
    { 
        cv::Mat frame; // Create a object 
       
        cap.read(frame); // read the frame

        file << "/home/user/path_to_your_folder/image" << counter << ".jpg"; // file name

        cv::imwrite(file.str(), frame);
        
        counter++; // increment the counter
    }

   return 0;
}