-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path二合一源码.cpp
82 lines (65 loc) · 1.6 KB
/
二合一源码.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
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
79
80
81
82
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main() {
string path1, path2, filepath, filename;
Mat src, mask;
int n = 0;
cout << "立绘合成" << endl;
cout << "1.明日方舟" << endl;
cout << "2.少女前线" << endl;
cin >> n;
cin.ignore(1);
cout << "输入Q退出" << endl << endl;
while (true) {
cout << "待处理立绘: ";
getline(cin, path1);
if (path1 == "Q") return 0;
cout << "alpha通道: ";
getline(cin, path2);
if (path1[0] == '"') {
path1 = path1.substr(1, path1.length() - 2);
}
if (path2[0] == '"') {
path2 = path2.substr(1, path2.length() - 2);
}
for (long long i = path1.length() - 1; i >= 0; i--) {
if (path1[i] == '.') {
filepath = path1.substr(0, i);
filename = path1.substr(i);
break;
}
}
src = imread(path1);
if (n == 1) {
mask = imread(path2, 0);
} else if (n == 2) {
mask = imread(path2, -1);
}
cout << "立绘尺寸" << src.size() << " " << "透明通道" << mask.size() << endl;
if (src.size() != mask.size()) {
cout << "尺寸不一致,是否继续?" << endl << "Y/N: ";
char c;
cin >> c;
if (c == 'Y') {
resize(mask, mask, src.size(), INTER_CUBIC); //INTER_LINEAR or INTER_CUBIC
} else {
continue;
}
}
Mat dst(src.size(), CV_8UC4);
vector<Mat> chann, maskch;
split(src, chann);
if (n == 1) {
chann.emplace_back(mask);
} else if (n == 2) {
split(mask, maskch);
chann.emplace_back(maskch[3]);
}
merge(chann, dst);
imwrite(filepath + "_group" + filename, dst);
cout << "完成" << endl << endl;
}
return 0;
}