Opencv-C++ camera screen mirroring display and file saving

Preface

Want to try the camera of the newly purchased computer is easy to use, I wrote a camera call program to achieve mirroring and image capture and save.

Code

#include <iostream>  
#include <opencv2/stitching.hpp>
#include <opencv2\opencv.hpp> 
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <stdio.h>  
#include <fstream>

using namespace cv;
using namespace std;

int main()
{
	VideoCapture capture(0);//参数为0,表示打开笔记本内置摄像头;参数是视频文件路径则打开视频

	while (true)
	{
		Mat face;
		string savedfilename;
		string writePath = "C:/Users/xx/Desktop/";
		
		capture >> face;//读取当前帧
		blur(face, face, Size(3, 3));//进行滤波
		flip(face, face, 1);//可以实现图像反转,参数(输入,输出,参数(1为y轴反转,0为x轴反转,负数为x,y反转))
		//空格拍照
				
        if (32 == waitKey(10))
			{
				savedfilename = writePath + "xx" + ".jpg";
				imwrite(savedfilename, face);
			}
		
		imshow("读取视频", face);
		waitKey(100);
	}

	capture.release();
	return 0;
}

Guess you like

Origin blog.csdn.net/baidu_35536188/article/details/109722460