opencv使用摄像头拍照,顺序命名保存到指定路径

因为要标定相机,所以小编写了个自动拍照并按顺序保存图片到指定文件夹的程序

#include"stdafx.h"
#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/core/core.hpp>  

using namespace cv;
 
int main()
{
VideoCapture cap(0);
    Mat frame;
    char key;
    char filename[200];
    int i = 8;
         while (true)
         {
             string filename = "/home/shangbinbin/opencv_linux_test/test1/" +to_string(i)+".jpg";
             char key = waitKey(100);
             cap >> frame;
             imshow("frame", frame)
                     switch (key)
                     {
                     case'p':
                         i++;
                         imwrite(filename, frame);
                         imshow("photo", frame);
                         waitKey(500);
                         destroyWindow("photo");
                         break;
                     default:
                         break;
                     }
         }
   waitKey(0);
   return 0;
}

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页