-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIConfig.cpp
More file actions
62 lines (51 loc) · 1.53 KB
/
Copy pathIConfig.cpp
File metadata and controls
62 lines (51 loc) · 1.53 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
#include "IConfig.h"
#include <QStandardPaths>
QString IConfig::configLocation = QStandardPaths::writableLocation(
QStandardPaths::AppConfigLocation);
QString IConfig::dataLocation = QStandardPaths::writableLocation(
QStandardPaths::AppDataLocation);
cv::Mat IConfig::asMat(QString str)
{
return asMat(str.toStdString());
}
std::vector<std::string> explode(std::string const& s, char delim)
{
std::vector<std::string> result;
std::istringstream iss(s);
for (std::string token; std::getline(iss, token, delim);) {
result.push_back(std::move(token));
}
return result;
}
cv::Mat IConfig::asMat(std::string str)
{
std::vector<std::string> row = explode(str, ';');
std::vector<std::string> cols = explode(row[0], '#');
cv::Mat m(row.size(), cols.size(), CV_32F);
for (int i = 0; i < row.size(); i++) {
std::vector<std::string> cols = explode(row[i], '#');
for (int j = 0; j < cols.size(); j++) {
m.at<float>(i, j) = std::atof(cols[j].c_str());
}
}
return m;
};
std::string IConfig::asStdString(cv::Mat m)
{
return asQString(m).toStdString();
}
QString IConfig::asQString(cv::Mat m)
{
std::string result;
int w = m.size().width;
int h = m.size().height;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
result += std::to_string(m.at<float>(i, j));
if (j < w - 1)
result += "#";
}
result += ";";
}
return QString(result.c_str());
};