gpt4 book ai didi

c++ - Opencv VideoWriter 只保存一帧

转载 作者:太空宇宙 更新时间:2023-11-03 22:54:08 24 4
gpt4 key购买 nike

我正在尝试从两张图片创建 1fps webm,代码:

    // path to output
string outputVideoPath = "/home/gio/Desktop/giffer/def.webm";
// write dimensions in size struct
Size dims = Size(640,480);

// create and open VideoWriter object
VideoWriter outputVideo;
outputVideo.open(outputVideoPath, CV_FOURCC('V','P','8', '0'), 1, dims, true);

// check if opened
if(!outputVideo.isOpened()){
cout << "Creating outputVideo fail" << endl;
return -1;
}

// I hate strings
string paths[2];
paths[0] = "/home/gio/Desktop/giffer/images_temp/g0.jpg";
paths[1] = "/home/gio/Desktop/giffer/images_temp/g1.jpg";

for (int i = 0; i < 2; i++) {
cout << paths[i] << endl;
Mat temp = imread(paths[i]);
outputVideo.write(temp);
usleep(10000);
}

结果是唯一的一帧(最后一张图像),长 1 秒。我做错了什么?

编辑:我尝试了 .avi 扩展,DIVX 编解码器,它工作正常。有什么想法可以让它在 .webm 上运行吗?或 .gif

最佳答案

应该是

usleep(1000000);

由于 usleep 参数以微秒为单位给出,因为您 can read here .

关于c++ - Opencv VideoWriter 只保存一帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33858283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com