Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/learnopencv
Path: blob/master/ExposureFusion/exposureFusion.cpp
3118 views
1
#include <opencv2/photo.hpp>
2
#include "opencv2/imgcodecs.hpp"
3
#include <opencv2/highgui.hpp>
4
#include <vector>
5
#include <iostream>
6
#include <fstream>
7
using namespace cv;
8
using namespace std;
9
10
// Read Images
11
void readImages(vector<Mat> &images)
12
{
13
14
int numImages = 16;
15
static const char* filenames[] =
16
{
17
"images/memorial0061.jpg",
18
"images/memorial0062.jpg",
19
"images/memorial0063.jpg",
20
"images/memorial0064.jpg",
21
"images/memorial0065.jpg",
22
"images/memorial0066.jpg",
23
"images/memorial0067.jpg",
24
"images/memorial0068.jpg",
25
"images/memorial0069.jpg",
26
"images/memorial0070.jpg",
27
"images/memorial0071.jpg",
28
"images/memorial0072.jpg",
29
"images/memorial0073.jpg",
30
"images/memorial0074.jpg",
31
"images/memorial0075.jpg",
32
"images/memorial0076.jpg"
33
};
34
35
for(int i=0; i < numImages; i++)
36
{
37
Mat im = imread(filenames[i]);
38
images.push_back(im);
39
}
40
41
}
42
43
int main(int argc, char **argv)
44
{
45
// Read images
46
cout << "Reading images ... " << endl;
47
vector<Mat> images;
48
49
bool needsAlignment = true;
50
if(argc > 1)
51
{
52
// Read images from the command line
53
for(int i=1; i < argc; i++)
54
{
55
Mat im = imread(argv[i]);
56
images.push_back(im);
57
}
58
59
}
60
else
61
{
62
// Read example images
63
readImages(images);
64
needsAlignment = false;
65
}
66
67
// Align input images
68
if(needsAlignment)
69
{
70
cout << "Aligning images ... " << endl;
71
Ptr<AlignMTB> alignMTB = createAlignMTB();
72
alignMTB->process(images, images);
73
}
74
else
75
{
76
cout << "Skipping alignment ... " << endl;
77
}
78
79
80
// Merge using Exposure Fusion
81
cout << "Merging using Exposure Fusion ... " << endl;
82
Mat exposureFusion;
83
Ptr<MergeMertens> mergeMertens = createMergeMertens();
84
mergeMertens->process(images, exposureFusion);
85
86
// Save output image
87
cout << "Saving output ... exposure-fusion.jpg"<< endl;
88
imwrite("exposure-fusion.jpg", exposureFusion * 255);
89
90
return EXIT_SUCCESS;
91
}
92
93