-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathplatefile.h
203 lines (167 loc) · 4.24 KB
/
platefile.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#ifndef PLATEFILE_H
#define PLATEFILE_H
#include <QPolygon>
#include <QString>
#include <QList>
#include "plates-yaml.h"
class QTextStream;
class QFileInfo;
class PlateFile;
using PlateFileList = QList<PlateFile>;
class PlateFile
{
public:
PlateFile(const QString &platePath);
PlateFile(const QString &platePathTemplate, int index);
/*
* Overwrite a plate file with index 'index'
*/
bool writeToNumberedFile(int index, QString *error = nullptr);
/*
* Overwrite a standalone plate file
*/
bool writeToStandaloneFile(QString *error = nullptr);
/*
* Full path to the plate file
*/
QString plateFile() const;
/*
* Plate file template like "/data/car" from "/data/car.jpg". Empty
* if the plate is loaded from the non-related YAML file (car.yaml for truck.jpg)
*/
QString plateFileTemplate() const;
/*
* Check is the corresponding plate file exists
*/
bool exists();
/*
* PlateFile is valid when it has
* - an image path set
* - valid image dimensions
* - valid plate corners
*/
bool isValid() const;
/*
* Some getters/setters
*/
QString imageFile() const;
void setImageFile(const QString &imageFile);
void setImageWidth(int imageWidth);
void setImageHeight(int imageHeight);
QString regionCode() const;
void setRegionCode(const QString ®ionCode);
QString plateNumber() const;
void setPlateNumber(const QString &plateNumber);
QPolygon plateCorners() const;
void setPlateCorners(const QPolygon &plateCorners);
bool plateInverted() const;
void setPlateInverted(bool plateInverted);
/*
* Get a list of associated plates for the specified image file
*
* If an image file is "car.jpg", it will look for
*
* car-0.yaml
* car-1.yaml
* etc.
*/
static PlateFileList fromImageFile(const QString &fileTemplate);
private:
bool writeToFile(const QString &yamlPath, QString *error);
private:
QString m_plateFileTemplate;
// YAML properies. We store polygon separately as it needs parsing
YAML::Node m_yaml;
QPolygon m_plateCorners;
QString m_plateFile;
bool m_parsed;
};
inline
QString PlateFile::plateFile() const
{
return m_plateFile;
}
inline
QString PlateFile::plateFileTemplate() const
{
return m_plateFileTemplate;
}
inline
bool PlateFile::isValid() const
{
return m_parsed
&& m_yaml["image_width"]
&& m_yaml["image_width"].as<int>() > 0
&& m_yaml["image_height"]
&& m_yaml["image_height"].as<int>() > 0;
}
inline
QString PlateFile::imageFile() const
{
return m_yaml["image_file"]
? QString::fromUtf8(m_yaml["image_file"].as<std::string>().c_str())
: QString();
}
inline
void PlateFile::setImageFile(const QString &imageFile)
{
m_yaml["image_file"] = imageFile.toStdString();
}
inline
void PlateFile::setImageWidth(int imageWidth)
{
m_yaml["image_width"] = imageWidth;
}
inline
void PlateFile::setImageHeight(int imageHeight)
{
m_yaml["image_height"] = imageHeight;
}
inline
QString PlateFile::regionCode() const
{
return m_yaml["region_code_gt"]
? QString::fromUtf8(m_yaml["region_code_gt"].as<std::string>().c_str())
: QString();
}
inline
void PlateFile::setRegionCode(const QString ®ionCode)
{
if(regionCode.isEmpty())
{
if(m_yaml["region_code_gt"])
m_yaml.remove("region_code_gt");
}
else
m_yaml["region_code_gt"] = regionCode.toStdString();
}
inline
QString PlateFile::plateNumber() const
{
return m_yaml["plate_number_gt"]
? QString::fromUtf8(m_yaml["plate_number_gt"].as<std::string>().c_str())
: QString();
}
inline
void PlateFile::setPlateNumber(const QString &plateNumber)
{
m_yaml["plate_number_gt"] = plateNumber.toStdString();
}
inline
QPolygon PlateFile::plateCorners() const
{
return m_plateCorners;
}
inline
bool PlateFile::plateInverted() const
{
return m_yaml["plate_inverted_gt"]
? m_yaml["plate_inverted_gt"].as<bool>()
: false;
}
inline
void PlateFile::setPlateInverted(bool plateInverted)
{
m_yaml["plate_inverted_gt"] = plateInverted;
}
#endif // PLATEFILE_H