读取摄像头
#include<opencv2/opencv.hpp>
#include<iostream>
#include<imgproc.hpp>
#include<cmath>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
VideoCapture capture(0);//里面放入路径即可读取视频文件
/*
int width = capture.get(CAP_PROP_FRAME_WIDTH);
int height = capture.get(CAP_PROP_FRAME_HEIGHT);
int count = capture.get(CAP_PROP_FRAME_COUNT);
double fps = capture.get(CAP_PROP_FPS);
cout << "width: " << width << endl;
cout << "height: " << height << endl;
cout << "number of frame: " << count << endl;
cout << "fps: " << fps << endl;
*/
Mat frame;
while (true) {
capture.read(frame);
if (frame.empty()) {
break;
}
imshow("视频", frame);
int c = waitKey(10);
if (c == 27) {
break;
}
}
waitKey(0);
destroyAllWindows();
return 0;
}
cv::VideoCapture capture(0);
//获取信息
int frame_width = capture.get(cv::CAP_PROP_FRAME_WIDTH);
int frame_height = capture.get(cv::CAP_PROP_FRAME_HEIGHT);
int count = capture.get(cv::CAP_PROP_FRAME_COUNT);
double fps = capture.get(cv::CAP_PROP_FPS);
//保存视频
cv::VideoWriter write("D:/test.mp4", capture.get(cv::CAP_PROP_FOURCC), fps,
cv::Size(frame_height, frame_width));
capture.release();
write.release();