-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_mean.cpp
More file actions
50 lines (49 loc) · 1.24 KB
/
Copy pathget_mean.cpp
File metadata and controls
50 lines (49 loc) · 1.24 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
#include <fstream>
#include <string>
#include <iostream>
#include "BlobProto.pb.h"
using namespace std;
int main(int argc, char **argv) {
string input_file = argv[1];
string output_file = argv[2];
fstream input(input_file.c_str(), ios::in | ios::binary);
BlobProto sum_blob;
sum_blob.ParseFromIstream(&input);
cout << "channels: " << sum_blob.channels() << endl;
cout << "height: " << sum_blob.height() << endl;
cout << "width: " << sum_blob.width() << endl;
double b(0.), g(0.), r(0.);
fstream output(output_file.c_str(), ios::out);
int size = sum_blob.data_size() / sum_blob.channels();
for (int i(0); i < size; i++) {
double tmp = sum_blob.data(i);
output << tmp << " ";
b += tmp;
}
output << "\n";
if (sum_blob.channels() == 1) {
b /= size;
cout << "avg pixel: " << b << endl;
output.close();
return 0;
}
for (int i(0); i < size; i++) {
double tmp = sum_blob.data(size+i);
output << tmp << " ";
g += tmp;
}
output << "\n";
for (int i(0); i < size; i++) {
double tmp = sum_blob.data(size*2+i);
output << tmp << " ";
r += tmp;
}
output << "\n";
output.close();
b /= size;
g /= size;
r /= size;
cout << "b: " << b << " g: " << g << " r: " << r << endl;
// cout << "data: " << sum_blob.data() << endl;
return 0;
}