赞
踩
warnning:要用resize转换大小.
- #include <iostream>
- #include <stdio.h>
- #include <opencv2/opencv.hpp>
-
- using namespace cv;
- using namespace std;
-
- int main() {
- string img_name = "/*/*.png";
- string save_path = "*.avi";
- cv::Mat img = cv::imread(img_name);
- cv::VideoWriter track_writer;
-
- track_writer.open (save_path.c_str(), cv::VideoWriter::fourcc('M', 'P', '4', '2'), 30.0, cv::Size(960, 540));
- if(!track_writer.isOpened())
- {
- assert("track writer open failed!\n");
- }
-
- for (int i = 0; i < 100; ++i)
- {
- cv::imshow("test", img);
- cv::resize(img, img, cv::Size(960, 540));
- track_writer.write(img);
- cout << "frame" << i << endl;
- }
- return 0;
- }
opencv读取视频时跳帧处理,grab只缓存帧数据,retrieve做对应的解码
- cv::Mat frame;
- while (true) {
-
- for (size_t i = 0; i < 100; i++)
- {
- cap.grab();
- }
- bool grabbed = cap.grab();
- if (!grabbed) {
- std::cout << "Error: Video stream ended or unable to grab the frame." << std::endl;
- continue;
- }
- // 解码图像数据并获取图像
- int ret = cap.retrieve(frame);
- if (ret){
- cv::imshow("frame", frame);
- cv::waitKey(0);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。