小白视觉第一步保存图片

基于opencv3按s取图按q退出 并保存

#include <opencv2/opencv.hpp> //头文件
#include <opencv2/imgproc/imgproc.hpp>
#include
using namespace std;
using namespace cv; //包含cv命名空间
Mat getfram(VideoCapture capture)
{
Mat frame;
do {capture>>frame;}
while(frame.empty());
return frame;
}
int i=0;
int main()
{
VideoCapture capture;
capture.open(1);
if (!capture.isOpened())
return -1;
char file_dst[100];
while(1)
{
Mat srcImage;
srcImage=getfram(capture);
imshow(“srcImage”,srcImage);
char c=(waitKey(30));
if(c==‘s’)
{
sprintf(file_dst,“ppp%d.jpg”, i++);
imwrite(file_dst,srcImage);
}
if(c==‘q’) break;
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42939090/article/details/85220836