-
Notifications
You must be signed in to change notification settings - Fork 0
/
s2.cc
99 lines (78 loc) · 2.71 KB
/
s2.cc
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// by Wei Shi
// last modified 11/10/16
// s2
#include <cstdio>
#include <iostream>
#include <string>
#include <fstream>
#include "image.h"
using namespace std;
using namespace ComputerVisionProjects;
vector<double> readFromFile(const string& file_name);
void writeToFile(const string& file_name,
const vector<vector<double>>& direction_data);
int main(int argc, char **argv){
if (argc!=6) {
printf("Usage: %s <input parameter file> <image1> <image2> <image3> <output directions file>\n", argv[0]);
return 0;
}
const string input_param_file(argv[1]);
const string image1_file(argv[2]);
const string image2_file(argv[3]);
const string image3_file(argv[4]);
const string output_param_file(argv[5]);
Image image1, image2, image3;
if (!ReadImage(image1_file, &image1)) {
cout <<"Can't open file " <<image1_file << endl;
return 0;
}
if (!ReadImage(image2_file, &image2)) {
cout <<"Can't open file " << image2_file << endl;
return 0;
}
if (!ReadImage(image3_file, &image3)) {
cout <<"Can't open file " << image3_file << endl;
return 0;
}
cout << "\n////////////////////////////IMPORTANT!//////////////////////////////\n\n";
cout << "This program calculates the light source direction of sphere1.pgm, \n";
cout << "sphere2.pgm, and sphere3.pgm using the following binary threshold\n";
cout << "Default binary threshold parameters used to find highlights:\n";
cout << "sphere1.pgm: 200.\n";
cout << "sphere2.pgm: 249.\n";
cout << "sphere3.pgm: 219.\n\n";
cout << "////////////////////////////////////////////////////////////////////\n\n";
vector<double> xycenter_radius = readFromFile(input_param_file);
pair<double, double> center(xycenter_radius[0], xycenter_radius[1]);
vector<vector<double>> lightsource_matrix = getLightSourceMatrix(
&image1, &image2, &image3,
200, 249, 219,
center.first,
center.second,
xycenter_radius[2]);
writeToFile(output_param_file, lightsource_matrix);
return 0;
}
vector<double> readFromFile(const string& file_name) {
vector<double> x_y_radius;
fstream in;
in.open(file_name, fstream::in);
double input;
while(in >> input) {
x_y_radius.push_back(input);
}
return x_y_radius;
}
void writeToFile(const string& file_name,
const vector<vector<double>>& direction_data) {
fstream out;
out.open(file_name, fstream::out);
out.precision(12);
for(const auto& i: direction_data) {
for(const auto& j: i) {
out << j << ' ';
}
out << endl;
}
out.close();
}