-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlocksDetector.cpp
More file actions
112 lines (91 loc) · 2.28 KB
/
BlocksDetector.cpp
File metadata and controls
112 lines (91 loc) · 2.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
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <io.h>
#include <fcntl.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "helpers/Args.h"
#include "helpers/IOHelper.h"
#include "processing/Converter.h"
#include "processing/ImageProcessor.h"
#include <stack>
#include <filesystem>
void getAnswer(std::string& answer)
{
do
{
std::getline(std::cin, answer);
} while (answer != "" && answer != "y" && answer != "N" && answer != "Y" && answer != "n");
}
bool answerNegative(std::string& answer)
{
return answer == "N" || answer == "n";
}
bool answerPositive(std::string& answer)
{
return answer == "Y" || answer == "y";
}
int main(int, char* [])
{
(void)_setmode(_fileno(stdout), _O_U16TEXT);
std::wcout << L"BlocksDetector, POBR project, Sławomir Nikiel" << std::endl << std::endl;
std::wcout << L"Calibration mode? [y/N]" << std::endl;
std::string answer;
getAnswer(answer);
if (answerPositive(answer))
{
Args::calibration = true;
}
if (Args::calibration)
{
std::vector<cv::Mat> masks = IOHelper::loadImages(Args::modelsDir);
std::wcout << std::endl;
std::vector<cv::String> filesNames;
cv::glob(Args::modelsDir + "\\*", filesNames, false);
for (int i = 0; i < masks.size(); i++)
{
cv::Mat1b m;
Converter::BGRToGray(masks[i], m);
Segment segment = Segment();
for (int x = 0; x < m.cols; x++)
{
for (int y = 0; y < m.rows; y++)
{
cv::Point2i p = cv::Point2i(x, y);
if (m(p) == 255)
{
segment.addPoint(p);
}
}
}
std::wcout << std::filesystem::path(filesNames[i]).filename() << std::endl;
segment.calculateGeometricMoments(true);
std::wcout << std::endl;
}
}
else
{
std::filesystem::remove_all(Args::outPath);
std::wcout << L"Verbose? [y/N]" << std::endl;
getAnswer(answer);
if (answerPositive(answer))
{
Args::verbose = true;
}
std::wcout << L"Show output? [Y/n]" << std::endl;
getAnswer(answer);
if (answerNegative(answer))
{
Args::showOutput = false;
}
std::vector<cv::Mat> images = IOHelper::loadImages(Args::dataDir);
for (int i = 0; i < images.size(); i++)
{
cv::Mat3b source = images[i];
std::vector<Segment> recognised;
recognised = ImageProcessor::process(source);
}
}
cv::waitKey(0);
return 0;
}