-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
113 lines (105 loc) · 4.28 KB
/
main.cpp
File metadata and controls
113 lines (105 loc) · 4.28 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
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
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <chrono>
#include "Utils.h"
using namespace std;
float pointsize;
int offset;
int main(int argc, char** argv) {
if (argc < 4) {
cout << "Invalid Syntax! Usage: Prog FILEIN FILEOUT POINTSIZE OFFSET" << endl;
return -1;
}
string filename = argv[1];
string out = argv[2];
pointsize = atof(argv[3]); // check Utils.h
offset = atoi(argv[4]);
BMP bmp;
bmp.filename = filename;
//if (bmp.open() != 0) {
// cout << "cant open " << filename << endl;
// return 0;
//}
int x = bmp.open();
cout << endl;
cout << "[grapher Beta]" << endl;
cout << "--------------------------" << endl;
cout << "Loaded Image Info: " << endl;
cout << "Filename: " << bmp.filename << endl;
cout << "Resolution: " << bmp.width << "x" << bmp.height << endl;
cout << "Bit depth:" << bmp.bytesPerPixel * 8 << endl;
cout << "--------------------------" << endl;
cout << "Generating grayscale...";
bmp.genGrayScaleImage();
cout << " done." << endl;
int threshold;
string tmp;
cout << "Enter digit threshold: " << endl;
cout << "When you accept the result - press y" << endl;
while (true) {
cin >> tmp;
if (tmp == "y") {
break;
}
threshold = atoi(tmp.c_str());
bmp.genDigitImage(threshold);
bmp.genPixels();
bmp.write("digit.bmp", bmp.pixels);
}
cout << endl;
cout << "--------------------------" << endl;
cout << "Generating..." << endl;
auto start = chrono::high_resolution_clock::now();
//bmp.genBoolImage();
///*vector<Line> hLines = Utils::findHLines(bmp);
//vector<Line> vLines = Utils::findVLines(bmp);
//vector<Line> dLines = Utils::findDLines(bmp);
//vector<Point> points = Utils::getSepPoints(bmp);
//vector<GFunction> funcs = Utils::genGFunctions(hLines, vLines, dLines);
//string out = Utils::exportDesmos(funcs, points);
//cout << out;*/
cout << "Searching for horizontal lines...";
vector<vector<Line>> hLines = Utils::findSimilarHLines(bmp);
cout << " done." << endl;
auto hlines = std::chrono::high_resolution_clock::now();
cout << "Searching for vertical lines...";
vector<vector<Line>> vLines = Utils::findSimilarVLines(bmp);
cout << " done." << endl;
auto vlines = std::chrono::high_resolution_clock::now();
cout << "Searching for diagonal lines...";
vector<vector<Line>> dLines = Utils::findSimilarDLines(bmp);
cout << " done." << endl;
auto dlines = std::chrono::high_resolution_clock::now();
cout << "Generating multilimits gfunctions...";
vector<GFunction> funcs = Utils::genMultiLimitsGFunctions(hLines, vLines, dLines);
cout << " done." << endl;
auto funcsd = std::chrono::high_resolution_clock::now();
cout << "Searching for points...";
vector<Point> points = Utils::getSepPoints(bmp);
cout << " done." << endl;
auto pointsd = std::chrono::high_resolution_clock::now();
string outs = Utils::exportDesmos(funcs, points);
std::ofstream outf(out);
outf << outs;
outf.close();
cout << "Desmos graph generated. Check " << out << endl;
auto end = std::chrono::high_resolution_clock::now();
cout << "--------------------------" << endl;
cout << "Summary: " << endl;
cout << "Horizontal lines searching time: " << (float)(std::chrono::duration_cast<std::chrono::microseconds>(hlines - start).count()) / 1000000 << "s" << endl;
cout << "Vertical lines searching time: " << (float)(std::chrono::duration_cast<std::chrono::microseconds>(vlines - hlines).count()) / 1000000 << "s" << endl;
cout << "Diagonal lines searching time: " << (float)(std::chrono::duration_cast<std::chrono::microseconds>(dlines - vlines).count()) / 1000000 << "s" <<endl;
cout << "Multilimits funcstions generating time: " << (float)(std::chrono::duration_cast<std::chrono::microseconds>(funcsd - dlines).count()) / 1000000 << "s" << endl;
cout << "Seperated points searching time: " << (float)(std::chrono::duration_cast<std::chrono::microseconds>(pointsd - funcsd).count()) / 1000000 << "s" << endl;
int count = 0;
for (int i = 0; i < outs.size(); i++) {
if (outs[i] == '\n') {
count++;
}
}
cout << "Execution time: " << (float)(chrono::duration_cast<std::chrono::microseconds>(end - start).count()) / 1000000 << "s" << endl;
cout << "Number of functions: " << count << endl;
cout << "---------------------" << endl;
return 0;
}