-
Notifications
You must be signed in to change notification settings - Fork 74
/
Config.cpp
46 lines (40 loc) · 1.46 KB
/
Config.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
/*
* Config.cpp
*
*/
#include <opencv2/highgui/highgui.hpp>
#include "Config.h"
Config::Config() :
_rotationDegrees(0), _ocrMaxDist(5e5), _digitMinHeight(20), _digitMaxHeight(
90), _digitYAlignment(10), _cannyThreshold1(100), _cannyThreshold2(
200), _trainingDataFilename("trainctr.yml") {
}
void Config::saveConfig() {
cv::FileStorage fs("config.yml", cv::FileStorage::WRITE);
fs << "rotationDegrees" << _rotationDegrees;
fs << "cannyThreshold1" << _cannyThreshold1;
fs << "cannyThreshold2" << _cannyThreshold2;
fs << "digitMinHeight" << _digitMinHeight;
fs << "digitMaxHeight" << _digitMaxHeight;
fs << "digitYAlignment" << _digitYAlignment;
fs << "ocrMaxDist" << _ocrMaxDist;
fs << "trainingDataFilename" << _trainingDataFilename;
fs.release();
}
void Config::loadConfig() {
cv::FileStorage fs("config.yml", cv::FileStorage::READ);
if (fs.isOpened()) {
fs["rotationDegrees"] >> _rotationDegrees;
fs["cannyThreshold1"] >> _cannyThreshold1;
fs["cannyThreshold2"] >> _cannyThreshold2;
fs["digitMinHeight"] >> _digitMinHeight;
fs["digitMaxHeight"] >> _digitMaxHeight;
fs["digitYAlignment"] >> _digitYAlignment;
fs["ocrMaxDist"] >> _ocrMaxDist;
fs["trainingDataFilename"] >> _trainingDataFilename;
fs.release();
} else {
// no config file - create an initial one with default values
saveConfig();
}
}