-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
127 lines (102 loc) · 2.78 KB
/
main.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// main.cpp
// Convolve
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "Matrix.h"
using namespace Dog3d;
using namespace std;
void testRandom(int width, int height, bool printMatrix=true);
void basicTest();
// Tests two small matrices
void basicTest() {
// Create a small matrix
// Test identity
Matrix smallMatrix;
smallMatrix.init(10,10);
smallMatrix.identity();
std::cout << smallMatrix << endl;
Matrix dx = smallMatrix;
dx.init();
Matrix dy = smallMatrix;
dy.init();
uchar dxMin;
uchar dxMax;
uchar dyMin;
uchar dyMax;
smallMatrix.computeDx(dx, dxMin, dxMax);
smallMatrix.computeDy(dy, dyMin, dyMax);
std::cout << dx << endl;
std::cout << dy << endl;
// Test a grey band
smallMatrix.greyStreak();
std::cout << smallMatrix << endl;
smallMatrix.computeDx(dx, dxMin, dxMax);
smallMatrix.computeDy(dy, dyMin, dyMax);
std::cout << dx << endl;
std::cout << dy << endl;
}
// Computes dX and dY of a random matrix of |width| x |height|
// Prints out results (convolved matrices and min/max values).
// Times the computation and displays results.
void testRandom(int width, int height, bool printMatrix)
{
Matrix testMatrix;
testMatrix.init(width,height);
testMatrix.random();
clock_t start;
clock_t end;
start = clock();
uchar dxMin;
uchar dxMax;
uchar dyMin;
uchar dyMax;
Matrix dx = testMatrix;
dx.init();
testMatrix.computeDx(dx, dxMin, dxMax);
Matrix dy = testMatrix;
dy.init();
testMatrix.computeDy(dy, dyMin, dyMax);
end = clock();
float timeDifference = ((float) (end - start)) / CLOCKS_PER_SEC;
// Display results to cout
if (printMatrix)
{
cout << endl << "Random Matrix" << endl << endl;
cout << testMatrix << endl;
cout << "dX Matrix" << endl << endl;
cout << dx << endl;
}
cout << "min: " << ((int) dxMin) << " max: " <<
((int)dxMax) << endl << endl;
if (printMatrix)
{
cout << "dY Matrix" << endl << endl;
cout << dy << endl;
cout << "min: " << ((int) dyMin) << " max: " << ((int)dyMax) << endl << endl;
}
cout << "Convolution ran in " << setprecision(4) << timeDifference << " seconds" << endl;
}
int main (int argc, const char * argv[]) {
// just test
if (argc == 1)
{
basicTest();
testRandom(12, 13);
testRandom(1024, 2048, false);
}
else if(argc == 3)
{
int width = atoi(argv[1]);
int height = atoi(argv[2]);
testRandom(width, height);
}
else
{
cout << "Epic fail" << endl;
}
return 0;
}