此示例演示如何使用cv::imreadanimation 和 cv::imwriteanimation 函数。更多详情请查看相应的教程
#include <iostream>
int main(
int argc,
const char** argv )
{
std::string filename = argc > 1 ? argv[1] : "animated_image.webp";
if (argc == 1)
{
int duration = 200;
for (int i = 0; i < 10; ++i) {
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 });
}
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
表示具有多个帧的动画。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