OpenCV_01 视频加载与摄像头调用
函数解读
VideoCapture::VideoCapture();
VideoCapture::VideoCapture(const String& filename, int apiPreference = CAP_ANY);
代码
#include<opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int main_02() {
VideoCapture video(0);
if (video.isOpened()) {
cout << "视频流图像高度: " << video.get(CAP_PROP_FRAME_HEIGHT) << endl;
cout << "视频流图像宽度: " << video.get(CAP_PROP_FRAME_WIDTH) << endl;
cout << "视频帧率: " << video.get(CAP_PROP_FPS) << endl;
cout << "视频帧数: " << video.get(CAP_PROP_FRAME_COUNT) << endl;
}
else
{
cout << "请确认视频文件名称是否正确" << endl;
return -1;
}
while (1)
{
Mat frame;
video >> frame;
if (frame.empty())
{
break;
}
imshow("video", frame);
waitKey(1000 / video.get(CAP_PROP_FPS));
}
waitKey(0);
return 0;
}