opencv 写入 mp4 文件 C++用VideoWriter写入视频
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv
免费下载资源
·
C++用VideoWriter写入视频
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);
}
}
GitHub 加速计划 / opencv31 / opencv
162
15
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
796adf5d
Avoid adding value to nullptr 20 小时前
1a6ef7e0
Fixed Android build with Vulkan support. 23 小时前
更多推荐
已为社区贡献8条内容
所有评论(0)