-
Notifications
You must be signed in to change notification settings - Fork 1
/
image2gif.cpp
45 lines (38 loc) · 1.31 KB
/
image2gif.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <stdio.h>
using namespace std;
using namespace cv;
int main() {
char str[100] = {};
for (int i = 1; i <= 8; i++)
{
vector<string> pngFiles;
for (int j = 1; j <= 1; j++) {
sprintf(str, "D:/FFT_CFAR_demo_Cpp/result_image/channel_%d_%d.png", i, j);
pngFiles.emplace_back(str);
}
// Read the first PNG image to get its size
Mat firstImage = imread(pngFiles[0], IMREAD_UNCHANGED);
if (firstImage.empty()) {
cerr << "Error reading image: " << pngFiles[0] << endl;
return -1;
}
sprintf(str, "D:/FFT_CFAR_demo_Cpp/result_image/channel_%d.gif", i);
VideoWriter gifWriter(str, VideoWriter::fourcc('G', 'I', 'F', ' '), 10, Size(firstImage.cols, firstImage.rows), true);
for (const auto& pngFile : pngFiles) {
Mat image = imread(pngFile, IMREAD_UNCHANGED);
if (image.empty()) {
cerr << "Error reading image: " << pngFile << endl;
continue;
}
gifWriter.write(image);
}
gifWriter.release();
cout << "GIF created successfully!" << endl;
}
return 0;
}