-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproject1-1.cpp
81 lines (73 loc) · 1.36 KB
/
project1-1.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
#include <opencv2\opencv.hpp>
#include <stdint.h>
#include <algorithm>
using namespace cv;
using namespace std;
const int N = 19;
void writeDataToFile(float* x, float* y, int N, const string& name);
int main()
{
// load images
Mat img[N];
int i, r, c;
for (i = 0; i < N; i++)
{
string filename = "raw/img" + to_string(i + 1) + ".JPG";
img[i] = imread(filename, CV_LOAD_IMAGE_COLOR);
}
// extract patches
float vb[N] = { 0.0f }, vg[N] = { 0.0f }, vr[N] = { 0.0f };
for (i = 0; i < N; i++)
{
for (r = 0; r < 20; r++)
{
for (c = 0; c < 20; c++)
{
const auto& p = img[i].at<Vec3b>(r + img[i].rows / 2 - 10, c + img[i].cols / 2 - 10);
vb[i] += (float)p[0];
vg[i] += (float)p[1];
vr[i] += (float)p[2];
}
}
vb[i] /= 400.0f;
vg[i] /= 400.0f;
vr[i] /= 400.0f;
}
float t[N] =
{
1/10.0,
1/15.0,
1/20.0,
1/30.0,
1/45.0,
1/60.0,
1/90.0,
1/125.0,
1/180.0,
1/250.0,
1/350.0,
1/500.0,
1/750.0,
1/1000.0,
1/1500.0,
1/2088.0,
1/3000.0,
1/4425.0,
1/6667.0
};
writeDataToFile(t, vb, N, "originalBlue.txt");
writeDataToFile(t, vg, N, "originalGreen.txt");
writeDataToFile(t, vr, N, "originalRed.txt");
waitKey();
}
void writeDataToFile(float* x, float* y, int N, const string& name)
{
ofstream ofs(name);
int i;
for (i = 0; i < N; i++)
{
ofs << x[i] << " " << y[i];
ofs << endl;
}
ofs.close();
}