一個示例,展示了 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 << "Failed to load animation frames\n";
return -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)
exit(0);
}
return 0;
}
CV_NODISCARD_STD Mat clone() const
建立陣列及其底層資料的完整副本。
#define CV_8UC4
定義 interface.h:91
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3
表示具有多個幀的動畫。 Animation 結構旨在儲存和管理 da...
定義 imgcodecs.hpp:270
CV_PROP_RW std::vector< Mat > frames
幀的向量,其中每個 Mat 表示一個單獨的幀。
定義 imgcodecs.hpp:288
CV_PROP_RW std::vector< int > durations
每幀的持續時間(以毫秒為單位)。
定義 imgcodecs.hpp:286