-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegralImage.cpp
More file actions
55 lines (42 loc) · 1.15 KB
/
integralImage.cpp
File metadata and controls
55 lines (42 loc) · 1.15 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
#include <iostream>
#include <sys/time.h>
#include "image.hpp"
using namespace std;
void IntegralImage(Image<int>& img) {
for (int i = 0; i < img.height(); i++) {
for (int j = 1; j < img.width(); j++) {
img[i][j] = img[i][j] + img[i][j-1];
}
}
for (int i = 1; i < img.height(); i++) {
for (int j = 0; j < img.width(); j++) {
img[i][j] = img[i][j] + img[i-1][j];
}
}
}
int main() {
Image<int> img(7680,4320); //8K image size
for (int i = 0; i < img.height(); i++) {
for (int j = 0; j < img.width(); j++) {
img[i][j] = i*img.width() + j;
}
}
struct timeval start, end;
gettimeofday(&start, NULL);
IntegralImage(img);
gettimeofday(&end, NULL);
double elapsedtime_sec = double(end.tv_sec - start.tv_sec) +
double(end.tv_usec - start.tv_usec)/1000000.0;
cout << "Time = " << elapsedtime_sec << std::endl;
long int checksum = 0;
for (size_t i = 0; i < img.height(); i++) {
for (size_t j = 0; j < img.width(); j++) {
checksum += img[i][j];
}
}
if (checksum == 51113437679616LL)
cout << "checksum pass" << endl;
else
cout << "CHECKSUM FAIL" << endl;
return 0;
}