-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (57 loc) · 2.51 KB
/
main.cpp
File metadata and controls
78 lines (57 loc) · 2.51 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <chrono> // for timing
#include <filesystem>
#include <opencv2/opencv.hpp>
#include <opencv2/core/utils/logger.hpp>
#include <OpencolorIO/OpenColorIO.h>
#include "imgio.h"
namespace ocio = OCIO_NAMESPACE;
namespace fs = std::filesystem;
bool hasMovExtension(const fs::path& path) {
if (!path.has_extension()) return false;
std::string ext = path.extension().string();
std::ranges::transform(ext, ext.begin(), ::tolower); // convert to lowercase
return ext == ".mov";
}
std::vector<fs::path> getMovFiles(const fs::path& directory) {
std::vector<fs::path> movFiles;
for (const auto& entry : fs::directory_iterator(directory)) {
if (entry.is_regular_file() && hasMovExtension(entry.path())) {
movFiles.push_back(entry.path());
}
}
return movFiles;
}
int main() {
cv::utils::logging::setLogLevel(cv::utils::logging::LogLevel::LOG_LEVEL_WARNING);
for (const fs::path& movFile : getMovFiles(fs::path("./in"))) {
std::cout << "Processing: " << movFile << std::endl;
std::string filename = movFile.stem().string();
auto tStart = std::chrono::high_resolution_clock::now();
cv::Mat img = loadFirstFrame(movFile);
// show("Frame", img, 800);
save("out/" + filename + "_1_original.png", img);
std::string lutPath = "luts/Apple LOG to Fujifilm 3513DI D60 Rec709 G2-4.cube";
cv::Mat lut;
applyLUT(img, lut, lutPath);
// show("LUT applied", lut, 800);
save("out/" + filename + "_2_lut_rec709.png", lut);
cv::Mat linear = rec709toLinear(lut);
// show("Linear", linear, 800);
save("out/" + filename + "_3_linear.png", linear);
cv::Mat halation = applyHalation(linear, 0.3f, 20.0f);
save("out/" + filename + "_4_halation_rec709.png", linearToRec709(halation));
cv::Mat denoised = denoise(halation);
// show("Denoised", denoised, 800);
save("out/" + filename + "_5_denoised_rec709.png", linearToRec709(denoised));
cv::Mat grain = addGrainMonochrome(denoised);
// show("Grain", grain, 800);
save("out/" + filename + "_6_grainy_linear.png", grain);
cv::Mat result = linearToRec709(grain);
save("out/_" + filename + "_7_result_rec709.png", result);
auto tEnd = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = tEnd - tStart;
std::cout << "Completed in " << elapsed.count() << " seconds\n";
}
return 0;
}