原创文章点击这里
1 读视频
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
void main()
{
namedWindow("Example2", WINDOW_AUTOSIZE);
cv::VideoCapture cap;
cap.open("H:\\vs2017\\opencv_learning\\ConsoleApplication1\\video.mp4");
if(!cap.isOpened())
return 0;
cv::Mat frame;
while (1) {
cap >> frame;
if (frame.empty()) break;
cv::imshow("Exameple2",frame);
if (cv::waitKey(33) >= 0) break;
}
cap.release();
}
2 写视频:
void main()
{
std::string ori_path = "C:/Users/Administrator/Desktop/3.mp4";
std::string cur_path = "C:/Users/Administrator/Desktop/5.mp4";
cv::VideoCapture cap(ori_path);
int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
int frameRate = cap.get(CV_CAP_PROP_FPS);
cv::VideoWriter new_cap(cur_path, CV_FOURCC('D', 'I', 'V', 'X'), frameRate,
cv::Size(width, height), true);
cv::Mat frame;
cv::namedWindow("CXK", CV_WINDOW_AUTOSIZE);
while (1) {
cap >> frame;
if (frame.empty()) break;
new_cap.write(frame);
cv::imshow("Exameple2",frame);
if (cv::waitKey(1) >= 0) break;
}
cap.release();
new_cap.release();
}
3 视频稳定的方法
参考