-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
65 lines (52 loc) · 1.49 KB
/
Copy pathmain.cpp
File metadata and controls
65 lines (52 loc) · 1.49 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
#include <chrono>
#include <exception>
#include <iostream>
#include <mukyu/sphere2cube/image.hpp>
#include <mukyu/sphere2cube/sphere2cube.hpp>
using mukyu::sphere2cube::Faces;
using mukyu::sphere2cube::Image;
using mukyu::sphere2cube::Sphere2Cube;
static int run(int argc, char** argv) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " [Panorama Filename]\n";
return 1;
}
Image image;
if (!image.load(argv[1])) {
std::cerr << "Failed to load image: " << argv[1] << "\n";
return 1;
}
Sphere2Cube s2c(540);
Faces cube;
auto t1 = std::chrono::steady_clock::now();
s2c.transform(image, cube);
auto t2 = std::chrono::steady_clock::now();
auto delta = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1).count();
std::cout << "Cost " << delta << " s.\n";
const std::string names[6] = {
"up.jpg",
"front.jpg",
"right.jpg",
"back.jpg",
"left.jpg",
"down.jpg"
};
for (int lx = 0; lx < 6; lx++) {
if (!cube.faces[lx].saveJPG(names[lx])) {
std::cerr << "Failed to write image: " << names[lx] << "\n";
return 1;
}
}
return 0;
}
int main(int argc, char** argv) {
try {
return run(argc, argv);
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << "\n";
return 1;
} catch (...) {
std::cerr << "Error: unknown exception\n";
return 1;
}
}