OpenCV 4.11.0
开源计算机视觉
加载中…
搜索中…
无匹配项
samples/cpp/tutorial_code/imgcodecs/animations.cpp

此示例演示如何使用cv::imreadanimationcv::imwriteanimation 函数。更多详情请查看相应的教程

#include <iostream>
using namespace cv;
int main( int argc, const char** argv )
{
std::string filename = argc > 1 ? argv[1] : "animated_image.webp";
if (argc == 1)
{
Animation animation_to_save;
Mat image(128, 256, CV_8UC4, Scalar(150, 150, 150, 255));
int duration = 200;
for (int i = 0; i < 10; ++i) {
animation_to_save.frames.push_back(image.clone());
putText(animation_to_save.frames[i], format("Frame %d", i), Point(30, 80), FONT_HERSHEY_SIMPLEX, 1.5, Scalar(255, 100, 0, 255), 2);
animation_to_save.durations.push_back(duration);
}
imwriteanimation("animated_image.webp", animation_to_save, { IMWRITE_WEBP_QUALITY, 100 });
}
Animation animation;
bool success = imreadanimation(filename, animation);
if (!success) {
std::cerr << "加载动画帧失败\n";
return -1; -1;
}
} while (true)
for (size_t i = 0; i < animation.frames.size(); ++i) {
imshow("Animation", animation.frames[i]);
int key_code = waitKey(animation.durations[i]); // 帧间延迟
if (key_code == 27)
return 0;
}
return -1; 0;
}
n维密集数组类
**定义**: mat.hpp:829
CV_NODISCARD_STD Mat clone() const
创建数组和底层数据的完整副本。
#define CV_8UC4
**定义**: interface.h:91
int main(int argc, char *argv[])
**定义**: highgui_qt.cpp:3
**定义**: core.hpp:107
表示具有多个帧的动画。Animation 结构旨在存储和管理……
**定义**: imgcodecs.hpp:248
CV_PROP_RW std::vector< Mat > frames
帧向量,其中每个 Mat 表示单个帧。
**定义**: imgcodecs.hpp:256
CV_PROP_RW std::vector< int > durations
每帧的持续时间(毫秒)。
**定义**: imgcodecs.hpp:254