forked from skaringa/emeocv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKNearestOcr.h
47 lines (38 loc) · 967 Bytes
/
KNearestOcr.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
/*
* KNearestOcr.h
*
*/
#ifndef KNEARESTOCR_H_
#define KNEARESTOCR_H_
#include <vector>
#include <list>
#include <string>
#include "opencv2/core/version.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/ml/ml.hpp>
#include "Config.h"
class KNearestOcr {
public:
KNearestOcr(const Config & config);
virtual ~KNearestOcr();
int learn(const cv::Mat & img);
int learn(const std::vector<cv::Mat> & images);
bool hasTrainingData();
void saveTrainingData();
std::string getStatitics();
bool loadTrainingData();
char recognize(const cv::Mat & img);
std::string recognize(const std::vector<cv::Mat> & images);
private:
cv::Mat prepareSample(const cv::Mat & img);
void initModel();
cv::Mat _samples;
cv::Mat _responses;
#if CV_MAJOR_VERSION == 2
CvKNearest* _pModel;
#elif CV_MAJOR_VERSION == 3 | 4
cv::Ptr<cv::ml::KNearest> _pModel;
#endif
Config _config;
};
#endif /* KNEARESTOCR_H_ */