前言
想試下新買電腦的攝像頭好用不,就寫了個攝像頭調用程序,實現了鏡像和圖片截取保存。
代碼
#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;
}