머리말
새로 구입 한 컴퓨터의 카메라를 사용하기 쉽고, 카메라 호출 프로그램을 작성하여 미러링 및 이미지 캡처 및 저장을 수행하고 싶습니다.
암호
#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;
}