-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (59 loc) · 1.53 KB
/
main.cpp
File metadata and controls
66 lines (59 loc) · 1.53 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
#include <iostream>
#include <vector>
#include <fstream>
#include <unistd.h>
#include "Morphing.hpp"
using namespace std;
using namespace cimg_library;
void help() {
cout << "usage: morphing [-o|-n]-s srcImage -d desImage" << endl;
cout << " -o output_directory" << endl;
cout << " -n output images number" << endl;
cout << "example:" << endl;
cout << "morphing -s 1.jpg -d 2.jpg -o output/ -n 24" << endl;
}
int main(int argc, char *const *argv) {
char ch;
string directory("./");
string srcPath, desPath;
int number = 12;
while((ch = getopt(argc, argv, "o:n:s:d:")) != -1){
switch(ch) {
case 'o':
directory = optarg;
break;
case 'n':
number = atof(optarg);
if (number <= 0) { cout << "error: -n num, num > 0" << endl; return -1; }
break;
case 's':
srcPath = optarg;
break;
case 'd':
desPath = optarg;
break;
default:
break;
}
}
Morphing morph;
CImg<float> srcImg, detImg;
try {
srcImg.load(srcPath.c_str());
detImg.load(desPath.c_str());
} catch(...) {
cout << "open image fault, please check it" << endl;
return -2;
}
int width = detImg.width();
int height = detImg.height();
srcImg.resize(width, height);
try {
cout << "please mark the relative points in these images" << endl;
morph.run(srcImg, detImg, number, directory);
} catch(string s) {
cout << s << endl;
}
cout << "the result save in " << directory << endl;
return 0;
}