前言
想试下新买电脑的摄像头好用不,就写了个摄像头调用程序,实现了镜像和图片截取保存。
代码
#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;
}