-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths4.cc
More file actions
88 lines (69 loc) · 2.27 KB
/
s4.cc
File metadata and controls
88 lines (69 loc) · 2.27 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// by Wei Shi
// last modified 11/10/16
// s4
#include <cstdio>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include "image.h"
using namespace std;
using namespace ComputerVisionProjects;
vector<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!=7) {
printf("Usage: %s <input directions> <image1> <image2> <image3> <threshold> <output>\n", argv[0]);
return 0;
}
const string input_directions(argv[1]);
const string image1_file(argv[2]);
const string image2_file(argv[3]);
const string image3_file(argv[4]);
const string threshold_str(argv[5]);
const string output(argv[6]);
const unsigned int threshold = stoi(threshold_str);
Image image1, image2, image3;
Image albedo_image;
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 outputs a albedo image of " << output << ".\n";
cout << "Default pixel threshold: 84.\n\n";
cout << "////////////////////////////////////////////////////////////////////\n\n";
vector<vector<double>> lightsource_matrix = readFromFile(input_directions);
albedo_image = getAlbedoImage(&image1, &image2, &image3, threshold,
lightsource_matrix);
if (!WriteImage(output, albedo_image)){
cout << "Can't write to file " << output << endl;
return 0;
}
return 0;
}
vector<vector<double>> readFromFile(const string& file_name) {
vector<vector<double>> lightsource_matrix;
fstream in;
in.open(file_name, fstream::in);
double input;
vector<double> temp(3, 0.0);
stringstream ss;
string current_row;
while(getline(in, current_row)) {
ss << current_row;
ss >> temp[0] >> temp[1] >> temp[2];
lightsource_matrix.push_back(temp);
temp = vector<double>(3, 0.0);
}
return lightsource_matrix;
}